-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
FasterXML/jackson-databind#1296 @JsonIncludeProperties #2771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
0b3e175
2186fbe
4191171
8e8671f
07e6bde
35c1f60
a3db197
d575e31
92decd8
5a89ec6
b740511
19a764d
7603c59
f1d122d
602ecd9
fbf4c12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,11 @@ public abstract class BeanDeserializerBase | |
*/ | ||
final protected Set<String> _ignorableProps; | ||
|
||
/** | ||
* Keep track of the the properties that needs to be specifically included. | ||
*/ | ||
final protected Set<String> _includableProps; | ||
|
||
/** | ||
* Flag that can be set to ignore and skip unknown properties. | ||
* If set, will not throw an exception for unknown properties. | ||
|
@@ -201,6 +206,7 @@ protected BeanDeserializerBase(BeanDeserializerBuilder builder, | |
BeanDescription beanDesc, | ||
BeanPropertyMap properties, Map<String, SettableBeanProperty> backRefs, | ||
Set<String> ignorableProps, boolean ignoreAllUnknown, | ||
Set<String> includableProps, | ||
boolean hasViews) | ||
{ | ||
super(beanDesc.getType()); | ||
|
@@ -211,6 +217,7 @@ protected BeanDeserializerBase(BeanDeserializerBuilder builder, | |
_backRefs = backRefs; | ||
_ignorableProps = ignorableProps; | ||
_ignoreAllUnknown = ignoreAllUnknown; | ||
_includableProps = includableProps; | ||
|
||
_anySetter = builder.getAnySetter(); | ||
List<ValueInjector> injectables = builder.getInjectables(); | ||
|
@@ -263,6 +270,7 @@ protected BeanDeserializerBase(BeanDeserializerBase src, boolean ignoreAllUnknow | |
_backRefs = src._backRefs; | ||
_ignorableProps = src._ignorableProps; | ||
_ignoreAllUnknown = ignoreAllUnknown; | ||
_includableProps = src._includableProps; | ||
_anySetter = src._anySetter; | ||
_injectables = src._injectables; | ||
_objectIdReader = src._objectIdReader; | ||
|
@@ -288,6 +296,7 @@ protected BeanDeserializerBase(BeanDeserializerBase src, NameTransformer unwrapp | |
_backRefs = src._backRefs; | ||
_ignorableProps = src._ignorableProps; | ||
_ignoreAllUnknown = (unwrapper != null) || src._ignoreAllUnknown; | ||
_includableProps = src._includableProps; | ||
_anySetter = src._anySetter; | ||
_injectables = src._injectables; | ||
_objectIdReader = src._objectIdReader; | ||
|
@@ -325,6 +334,7 @@ public BeanDeserializerBase(BeanDeserializerBase src, ObjectIdReader oir) | |
_backRefs = src._backRefs; | ||
_ignorableProps = src._ignorableProps; | ||
_ignoreAllUnknown = src._ignoreAllUnknown; | ||
_includableProps = src._includableProps; | ||
_anySetter = src._anySetter; | ||
_injectables = src._injectables; | ||
|
||
|
@@ -351,17 +361,26 @@ public BeanDeserializerBase(BeanDeserializerBase src, ObjectIdReader oir) | |
} | ||
|
||
public BeanDeserializerBase(BeanDeserializerBase src, Set<String> ignorableProps) | ||
{ | ||
this(src, ignorableProps, src._includableProps); | ||
} | ||
|
||
/** | ||
* @since 2.12 | ||
*/ | ||
public BeanDeserializerBase(BeanDeserializerBase src, Set<String> ignorableProps, Set<String> includableProps) | ||
{ | ||
super(src._beanType); | ||
_beanType = src._beanType; | ||
|
||
_valueInstantiator = src._valueInstantiator; | ||
_delegateDeserializer = src._delegateDeserializer; | ||
_propertyBasedCreator = src._propertyBasedCreator; | ||
|
||
_backRefs = src._backRefs; | ||
_ignorableProps = ignorableProps; | ||
_ignoreAllUnknown = src._ignoreAllUnknown; | ||
_includableProps = includableProps; | ||
_anySetter = src._anySetter; | ||
_injectables = src._injectables; | ||
|
||
|
@@ -375,9 +394,10 @@ public BeanDeserializerBase(BeanDeserializerBase src, Set<String> ignorableProps | |
|
||
// 01-May-2016, tatu: [databind#1217]: Remove properties from mapping, | ||
// to avoid them being deserialized | ||
_beanProperties = src._beanProperties.withoutProperties(ignorableProps); | ||
_beanProperties = src._beanProperties.withoutProperties(ignorableProps, includableProps); | ||
} | ||
|
||
|
||
/** | ||
* @since 2.8 | ||
*/ | ||
|
@@ -394,6 +414,7 @@ protected BeanDeserializerBase(BeanDeserializerBase src, BeanPropertyMap beanPro | |
_backRefs = src._backRefs; | ||
_ignorableProps = src._ignorableProps; | ||
_ignoreAllUnknown = src._ignoreAllUnknown; | ||
_includableProps = src._includableProps; | ||
_anySetter = src._anySetter; | ||
_injectables = src._injectables; | ||
_objectIdReader = src._objectIdReader; | ||
|
@@ -411,7 +432,15 @@ protected BeanDeserializerBase(BeanDeserializerBase src, BeanPropertyMap beanPro | |
|
||
public abstract BeanDeserializerBase withObjectIdReader(ObjectIdReader oir); | ||
|
||
public abstract BeanDeserializerBase withIgnorableProperties(Set<String> ignorableProps); | ||
public BeanDeserializerBase withIgnorableProperties(Set<String> ignorableProps) { | ||
return withIgnorableProperties(ignorableProps, _includableProps); | ||
} | ||
|
||
public abstract BeanDeserializerBase withIgnorableProperties(Set<String> ignorableProps, Set<String> includableProps); | ||
cowtowncoder marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (note to self, mostly) Makes sense to use different name, I think, |
||
|
||
public BeanDeserializerBase withIncludableProperties(Set<String> includableProperties) { | ||
return withIgnorableProperties(_ignorableProps, includableProperties); | ||
} | ||
|
||
// NOTE! To be made `abstract` in 2.12 or later | ||
/** | ||
|
@@ -422,7 +451,7 @@ public BeanDeserializerBase withIgnoreAllUnknown(boolean ignoreUnknown) { | |
if (ignoreUnknown == _ignoreAllUnknown) { | ||
return this; | ||
} | ||
return withIgnorableProperties(_ignorableProps); | ||
return withIgnorableProperties(_ignorableProps, _includableProps); | ||
} | ||
|
||
/** | ||
|
@@ -469,10 +498,10 @@ public void resolve(DeserializationContext ctxt) throws JsonMappingException | |
// 22-Jan-2018, tatu: May need to propagate "ignorable" status (from `Access.READ_ONLY` | ||
// or perhaps class-ignorables) into Creator properties too. Can not just delete, | ||
// at this point, but is needed for further processing down the line | ||
if (_ignorableProps != null) { | ||
if (_ignorableProps != null || _includableProps != null) { | ||
for (int i = 0, end = creatorProps.length; i < end; ++i) { | ||
SettableBeanProperty prop = creatorProps[i]; | ||
if (_ignorableProps.contains(prop.getName())) { | ||
if (IgnorePropertiesUtil.shouldIgnore(prop.getName(), _ignorableProps, _includableProps)) { | ||
creatorProps[i].markAsIgnorable(); | ||
} | ||
} | ||
|
@@ -773,6 +802,21 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt, | |
contextual = contextual.withIgnoreAllUnknown(true); | ||
} | ||
} | ||
JsonIncludeProperties.Value inclusions = intr.findPropertyInclusions(accessor); | ||
if (inclusions != null) { | ||
Set<String> included = inclusions.getIncluded(); | ||
Set<String> prev = contextual._includableProps; | ||
if (prev != null && included != null) { | ||
Set<String> newIncluded = new HashSet<>(); | ||
// Make the intersection with the previously included properties. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not 100% sure if this is the right default: seems like there would be 3 possibilities:
Now, adding "mode" or something in |
||
for(String prop : prev) { | ||
if (included.contains(prop)) { | ||
newIncluded.add(prop); | ||
} | ||
} | ||
contextual = contextual.withIncludableProperties(newIncluded); | ||
} | ||
} | ||
} | ||
|
||
// One more thing: are we asked to serialize POJO as array? | ||
|
@@ -1587,7 +1631,8 @@ protected void handleUnknownVanilla(JsonParser p, DeserializationContext ctxt, | |
Object beanOrBuilder, String propName) | ||
throws IOException | ||
{ | ||
if (_ignorableProps != null && _ignorableProps.contains(propName)) { | ||
|
||
if (IgnorePropertiesUtil.shouldIgnore(propName, _ignorableProps, _includableProps)) { | ||
handleIgnoredProperty(p, ctxt, beanOrBuilder, propName); | ||
} else if (_anySetter != null) { | ||
try { | ||
|
@@ -1615,7 +1660,7 @@ protected void handleUnknownProperty(JsonParser p, DeserializationContext ctxt, | |
p.skipChildren(); | ||
return; | ||
} | ||
if (_ignorableProps != null && _ignorableProps.contains(propName)) { | ||
if (IgnorePropertiesUtil.shouldIgnore(propName, _ignorableProps, _includableProps)) { | ||
handleIgnoredProperty(p, ctxt, beanOrClass, propName); | ||
} | ||
// Otherwise use default handling (call handler(s); if not | ||
|
Uh oh!
There was an error while loading. Please reload this page.