Skip to content

Commit 20a1b6b

Browse files
committed
Merge branch '2.9' of https://github.com/FasterXML/jackson-databind into 2.9
2 parents c612c1e + 562484c commit 20a1b6b

File tree

14 files changed

+211
-45
lines changed

14 files changed

+211
-45
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,3 +738,9 @@ Alexander Skvortcov (askvortcov@github)
738738
* Reported #1853: Deserialise from Object (using Creator methods) returns field name
739739
instead of value
740740
(2.9.4)
741+
742+
Joe Schafer (jschaf@github)
743+
* Reported #1906: Add string format specifier for error message in `PropertyValueBuffer`
744+
(2.9.4)
745+
* Reported #1907: Remove `getClass()` from `_valueType` argument for error reporting
746+
(2.9.4)

release-notes/VERSION-2.x

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
------------------------------------------------------------------------
12
Project: jackson-databind
23
------------------------------------------------------------------------
4+
35
=== Releases ===
4-
------------------------------------------------------------------------
56

67
2.9.4 (not yet released)
78

@@ -28,6 +29,12 @@ Project: jackson-databind
2829
(reported by reda-alaoui@github)
2930
#1895: Per-type config override "JsonFormat.Shape.OBJECT" for Map.Entry not working
3031
(reported by mcortella@github)
32+
#1899: Another two gadgets to exploit default typing issue in jackson-databind
33+
(reported by OneSourceCat@github)
34+
#1906: Add string format specifier for error message in `PropertyValueBuffer`
35+
(reported by Joe S)
36+
#1907: Remove `getClass()` from `_valueType` argument for error reporting
37+
(reported by Joe S)
3138

3239
2.9.3 (09-Dec-2017)
3340

@@ -192,9 +199,11 @@ Project: jackson-databind
192199

193200
2.8.11.1 (not yet released)
194201

195-
#1872 `NullPointerException` in `SubTypeValidator.validateSubType` when
202+
#1872: `NullPointerException` in `SubTypeValidator.validateSubType` when
196203
validating Spring interface
197204
(reported by Rob W)
205+
#1899: Another two gadgets to exploit default typing issue in jackson-databind
206+
(reported by OneSourceCat@github)
198207

199208
2.8.11 (24-Dec-2017)
200209

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,15 +432,26 @@ public BeanDeserializerBase withBeanProperties(BeanPropertyMap props) {
432432
* This is needed to handle recursive and transitive dependencies.
433433
*/
434434
@Override
435-
public void resolve(DeserializationContext ctxt)
436-
throws JsonMappingException
435+
public void resolve(DeserializationContext ctxt) throws JsonMappingException
437436
{
438437
ExternalTypeHandler.Builder extTypes = null;
439438
// if ValueInstantiator can use "creator" approach, need to resolve it here...
440439
SettableBeanProperty[] creatorProps;
441440

442441
if (_valueInstantiator.canCreateFromObjectWith()) {
443442
creatorProps = _valueInstantiator.getFromObjectArguments(ctxt.getConfig());
443+
444+
// 22-Jan-2018, tatu: May need to propagate "ignorable" status (from `Access.READ_ONLY`
445+
// or perhaps class-ignorables) into Creator properties too. Can not just delete,
446+
// at this point, but is needed for further processing down the line
447+
if (_ignorableProps != null) {
448+
for (int i = 0, end = creatorProps.length; i < end; ++i) {
449+
SettableBeanProperty prop = creatorProps[i];
450+
if (_ignorableProps.contains(prop.getName())) {
451+
creatorProps[i].markAsIgnorable();
452+
}
453+
}
454+
}
444455
} else {
445456
creatorProps = null;
446457
}
@@ -451,6 +462,8 @@ public void resolve(DeserializationContext ctxt)
451462
// types (see [databind#1575] f.ex).
452463
// First loop: find deserializer if not yet known, but do not yet
453464
// contextualize (since that can lead to problems with self-references)
465+
// 22-Jan-2018, tatu: NOTE! Need not check for `isIgnorable` as that can
466+
// only happen for props in `creatorProps`
454467

455468
for (SettableBeanProperty prop : _beanProperties) {
456469
if (!prop.hasValueDeserializer()) {
@@ -524,7 +537,7 @@ public void resolve(DeserializationContext ctxt)
524537
}
525538
}
526539
// "any setter" may also need to be resolved now
527-
if (_anySetter != null && !_anySetter.hasValueDeserializer()) {
540+
if ((_anySetter != null) && !_anySetter.hasValueDeserializer()) {
528541
_anySetter = _anySetter.withValueDeserializer(findDeserializer(ctxt,
529542
_anySetter.getType(), _anySetter.getProperty()));
530543
}

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,6 @@ public JsonDeserializer<?> build()
348348
{
349349
Collection<SettableBeanProperty> props = _properties.values();
350350
_fixAccess(props);
351-
352351
BeanPropertyMap propertyMap = BeanPropertyMap.construct(props,
353352
_config.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES),
354353
_collectAliases(props));

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ protected void addBeanProps(DeserializationContext ctxt,
464464
.getDefaultPropertyIgnorals(beanDesc.getBeanClass(),
465465
beanDesc.getClassInfo());
466466
Set<String> ignored;
467-
468467
if (ignorals != null) {
469468
boolean ignoreAny = ignorals.getIgnoreUnknown();
470469
builder.setIgnoreUnknownProperties(ignoreAny);
@@ -499,7 +498,6 @@ protected void addBeanProps(DeserializationContext ctxt,
499498
// Ok: let's then filter out property definitions
500499
List<BeanPropertyDefinition> propDefs = filterBeanProps(ctxt,
501500
beanDesc, builder, beanDesc.findProperties(), ignored);
502-
503501
// After which we can let custom code change the set
504502
if (_factoryConfig.hasDeserializerModifiers()) {
505503
for (BeanDeserializerModifier mod : _factoryConfig.deserializerModifiers()) {

src/main/java/com/fasterxml/jackson/databind/deser/CreatorProperty.java

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ public class CreatorProperty
4343
*/
4444
protected final Object _injectableValueId;
4545

46-
/**
47-
* @since 2.1
48-
*/
49-
protected final int _creatorIndex;
50-
5146
/**
5247
* In special cases, when implementing "updateValue", we cannot use
5348
* constructors or factory methods, but have to fall back on using a
@@ -61,6 +56,22 @@ public class CreatorProperty
6156
*/
6257
protected SettableBeanProperty _fallbackSetter;
6358

59+
/**
60+
* @since 2.1
61+
*/
62+
protected final int _creatorIndex;
63+
64+
/**
65+
* Marker flag that may have to be set during construction, to indicate that
66+
* although property may have been constructed and added as a placeholder,
67+
* it represents something that should be ignored during deserialization.
68+
* This mostly concerns Creator properties which may not be easily deleted
69+
* during processing.
70+
*
71+
* @since 2.9.4
72+
*/
73+
protected boolean _ignorable;
74+
6475
/**
6576
* @param name Name of the logical property
6677
* @param type Type of the property, used to find deserializer
@@ -94,18 +105,20 @@ public CreatorProperty(PropertyName name, JavaType type, PropertyName wrapperNam
94105
protected CreatorProperty(CreatorProperty src, PropertyName newName) {
95106
super(src, newName);
96107
_annotated = src._annotated;
97-
_creatorIndex = src._creatorIndex;
98108
_injectableValueId = src._injectableValueId;
99109
_fallbackSetter = src._fallbackSetter;
110+
_creatorIndex = src._creatorIndex;
111+
_ignorable = src._ignorable;
100112
}
101113

102114
protected CreatorProperty(CreatorProperty src, JsonDeserializer<?> deser,
103115
NullValueProvider nva) {
104116
super(src, deser, nva);
105117
_annotated = src._annotated;
106-
_creatorIndex = src._creatorIndex;
107118
_injectableValueId = src._injectableValueId;
108119
_fallbackSetter = src._fallbackSetter;
120+
_creatorIndex = src._creatorIndex;
121+
_ignorable = src._ignorable;
109122
}
110123

111124
@Override
@@ -143,6 +156,22 @@ public void setFallbackSetter(SettableBeanProperty fallbackSetter) {
143156
_fallbackSetter = fallbackSetter;
144157
}
145158

159+
@Override
160+
public void markAsIgnorable() {
161+
_ignorable = true;
162+
}
163+
164+
@Override
165+
public boolean isIgnorable() {
166+
return _ignorable;
167+
}
168+
169+
/*
170+
/**********************************************************
171+
/* Injection support
172+
/**********************************************************
173+
*/
174+
146175
/**
147176
* Method that can be called to locate value to be injected for this
148177
* property, if it is configured for this.

src/main/java/com/fasterxml/jackson/databind/deser/SettableBeanProperty.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ public void fixAccess(DeserializationConfig config) {
331331
;
332332
}
333333

334+
/**
335+
* @since 2.9.4
336+
*/
337+
public void markAsIgnorable() { }
338+
339+
/**
340+
* @since 2.9.4
341+
*/
342+
public boolean isIgnorable() { return false; }
343+
334344
/*
335345
/**********************************************************
336346
/* BeanProperty impl

src/main/java/com/fasterxml/jackson/databind/deser/impl/CreatorCollector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ public void addPropertyCreator(AnnotatedWithParams creator,
178178
String name = properties[i].getName();
179179
// Need to consider Injectables, which may not have
180180
// a name at all, and need to be skipped
181-
if (name.length() == 0
182-
&& properties[i].getInjectableValueId() != null) {
181+
if (name.isEmpty() && (properties[i].getInjectableValueId() != null)) {
183182
continue;
184183
}
185184
Integer old = names.put(name, Integer.valueOf(i));

src/main/java/com/fasterxml/jackson/databind/deser/impl/PropertyBasedCreator.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,24 @@ protected PropertyBasedCreator(DeserializationContext ctxt,
7171
if (addAliases) {
7272
final DeserializationConfig config = ctxt.getConfig();
7373
for (SettableBeanProperty prop : creatorProps) {
74-
List<PropertyName> aliases = prop.findAliases(config);
75-
if (!aliases.isEmpty()) {
76-
for (PropertyName pn : aliases) {
77-
_propertyLookup.put(pn.getSimpleName(), prop);
74+
// 22-Jan-2018, tatu: ignorable entries should be ignored, even if got aliases
75+
if (!prop.isIgnorable()) {
76+
List<PropertyName> aliases = prop.findAliases(config);
77+
if (!aliases.isEmpty()) {
78+
for (PropertyName pn : aliases) {
79+
_propertyLookup.put(pn.getSimpleName(), prop);
80+
}
7881
}
7982
}
8083
}
8184
}
8285
for (int i = 0; i < len; ++i) {
8386
SettableBeanProperty prop = creatorProps[i];
8487
_allProperties[i] = prop;
85-
_propertyLookup.put(prop.getName(), prop);
88+
// 22-Jan-2018, tatu: ignorable entries should be skipped
89+
if (!prop.isIgnorable()) {
90+
_propertyLookup.put(prop.getName(), prop);
91+
}
8692
}
8793
}
8894

src/main/java/com/fasterxml/jackson/databind/deser/impl/PropertyValueBuffer.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ public Object getParameter(SettableBeanProperty prop)
131131
value = _creatorParameters[prop.getCreatorIndex()] = _findMissing(prop);
132132
}
133133
if (value == null && _context.isEnabled(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES)) {
134-
return _context.reportInputMismatch(prop, String.format(
135-
"Null value for creator property '%s'; DeserializationFeature.FAIL_ON_NULL_FOR_CREATOR_PARAMETERS enabled",
136-
prop.getName(), prop.getCreatorIndex()));
134+
return _context.reportInputMismatch(prop,
135+
"Null value for creator property '%s' (index %d); `DeserializationFeature.FAIL_ON_NULL_FOR_CREATOR_PARAMETERS` enabled",
136+
prop.getName(), prop.getCreatorIndex());
137137
}
138138
return value;
139139
}
@@ -172,7 +172,7 @@ public Object[] getParameters(SettableBeanProperty[] props)
172172
if (_creatorParameters[ix] == null) {
173173
SettableBeanProperty prop = props[ix];
174174
_context.reportInputMismatch(prop.getType(),
175-
"Null value for creator property '%s' (index %d); DeserializationFeature.FAIL_ON_NULL_FOR_CREATOR_PARAMETERS enabled",
175+
"Null value for creator property '%s' (index %d); `DeserializationFeature.FAIL_ON_NULL_FOR_CREATOR_PARAMETERS` enabled",
176176
prop.getName(), props[ix].getCreatorIndex());
177177
}
178178
}
@@ -191,14 +191,13 @@ protected Object _findMissing(SettableBeanProperty prop) throws JsonMappingExcep
191191
}
192192
// Second: required?
193193
if (prop.isRequired()) {
194-
_context.reportInputMismatch(prop, String.format(
195-
"Missing required creator property '%s' (index %d)",
196-
prop.getName(), prop.getCreatorIndex()));
194+
_context.reportInputMismatch(prop, "Missing required creator property '%s' (index %d)",
195+
prop.getName(), prop.getCreatorIndex());
197196
}
198197
if (_context.isEnabled(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES)) {
199-
_context.reportInputMismatch(prop, String.format(
200-
"Missing creator property '%s' (index %d); DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES enabled",
201-
prop.getName(), prop.getCreatorIndex()));
198+
_context.reportInputMismatch(prop,
199+
"Missing creator property '%s' (index %d); `DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES` enabled",
200+
prop.getName(), prop.getCreatorIndex());
202201
}
203202
// Third: default value
204203
JsonDeserializer<Object> deser = prop.getValueDeserializer();

0 commit comments

Comments
 (0)