Skip to content

Commit 2dbd816

Browse files
committed
Fixed #1438
1 parent 27d07a2 commit 2dbd816

File tree

3 files changed

+59
-23
lines changed

3 files changed

+59
-23
lines changed

release-notes/CREDITS

+2
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ Ievgen Pianov (pyanoveugen@github)
368368
Jayson Minard (apatrida@github)
369369
* Reported #1005: Synthetic constructors confusing Jackson data binding
370370
(2.6.4)
371+
* Reported #1438: `ACCEPT_CASE_INSENSITIVE_PROPERTIES` is not respected for creator properties
372+
(2.8.5)
371373

372374
David Bakin (david-bakin@github)
373375
* Reported #1013: `@JsonUnwrapped` is not treated as assuming `@JsonProperty("")`

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Project: jackson-databind
1212
with more than one argument
1313
#1432: Off by 1 bug in PropertyValueBuffer
1414
(reported by Kevin D)
15+
#1438: `ACCEPT_CASE_INSENSITIVE_PROPERTIES` is not respected for creator properties
16+
(reported by Jayson M)
1517
#1439: NPE when using with filter id, serializing `java.util.Map` types
1618
#1441: Failure with custom Enum key deserializer, polymorphic types
1719
(reported by Nathanial O)

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

+55-23
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import com.fasterxml.jackson.databind.DeserializationContext;
1010
import com.fasterxml.jackson.databind.JsonMappingException;
11+
import com.fasterxml.jackson.databind.MapperFeature;
1112
import com.fasterxml.jackson.databind.deser.SettableBeanProperty;
1213
import com.fasterxml.jackson.databind.deser.ValueInstantiator;
1314

@@ -21,38 +22,47 @@
2122
*/
2223
public final class PropertyBasedCreator
2324
{
25+
/**
26+
* Number of properties: usually same as size of {@link #_propertyLookup},
27+
* but not necessarily, when we have unnamed injectable properties.
28+
*/
29+
protected final int _propertyCount;
30+
31+
/**
32+
* Helper object that knows how to actually construct the instance by
33+
* invoking creator method with buffered arguments.
34+
*/
2435
protected final ValueInstantiator _valueInstantiator;
25-
36+
2637
/**
2738
* Map that contains property objects for either constructor or factory
2839
* method (whichever one is null: one property for each
2940
* parameter for that one), keyed by logical property name
3041
*/
3142
protected final HashMap<String, SettableBeanProperty> _propertyLookup;
3243

33-
/**
34-
* Number of properties: usually same as size of {@link #_propertyLookup},
35-
* but not necessarily, when we have unnamed injectable properties.
36-
*/
37-
protected final int _propertyCount;
38-
3944
/**
4045
* Array that contains properties that expect value to inject, if any;
4146
* null if no injectable values are expected.
4247
*/
4348
protected final SettableBeanProperty[] _allProperties;
44-
49+
4550
/*
4651
/**********************************************************
4752
/* Construction, initialization
4853
/**********************************************************
4954
*/
50-
55+
5156
protected PropertyBasedCreator(ValueInstantiator valueInstantiator,
52-
SettableBeanProperty[] creatorProps)
57+
SettableBeanProperty[] creatorProps,
58+
boolean caseInsensitive)
5359
{
5460
_valueInstantiator = valueInstantiator;
55-
_propertyLookup = new HashMap<String, SettableBeanProperty>();
61+
if (caseInsensitive) {
62+
_propertyLookup = new CaseInsensitiveMap();
63+
} else {
64+
_propertyLookup = new HashMap<String, SettableBeanProperty>();
65+
}
5666
final int len = creatorProps.length;
5767
_propertyCount = len;
5868
_allProperties = new SettableBeanProperty[len];
@@ -79,24 +89,17 @@ public static PropertyBasedCreator construct(DeserializationContext ctxt,
7989
prop = prop.withValueDeserializer(ctxt.findContextualValueDeserializer(prop.getType(), prop));
8090
}
8191
creatorProps[i] = prop;
82-
}
83-
return new PropertyBasedCreator(valueInstantiator, creatorProps);
92+
}
93+
return new PropertyBasedCreator(valueInstantiator, creatorProps,
94+
ctxt.isEnabled(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES));
8495
}
8596

86-
// 05-May-2015, tatu: Does not seem to be used, commented out in 2.6
87-
/*
88-
public void assignDeserializer(SettableBeanProperty prop, JsonDeserializer<Object> deser) {
89-
prop = prop.withValueDeserializer(deser);
90-
_properties.put(prop.getName(), prop);
91-
}
92-
*/
93-
9497
/*
9598
/**********************************************************
9699
/* Accessors
97100
/**********************************************************
98101
*/
99-
102+
100103
public Collection<SettableBeanProperty> properties() {
101104
return _propertyLookup.values();
102105
}
@@ -113,7 +116,7 @@ public SettableBeanProperty findCreatorProperty(int propertyIndex) {
113116
}
114117
return null;
115118
}
116-
119+
117120
/*
118121
/**********************************************************
119122
/* Building process
@@ -146,4 +149,33 @@ public Object build(DeserializationContext ctxt, PropertyValueBuffer buffer) thr
146149
}
147150
return bean;
148151
}
152+
153+
/*
154+
/**********************************************************
155+
/* Helper classes
156+
/**********************************************************
157+
*/
158+
159+
/**
160+
* Simple override of standard {@link java.util.HashMap} to support
161+
* case-insensitive access to creator properties.
162+
*
163+
* @since 2.8.5
164+
*/
165+
static class CaseInsensitiveMap extends HashMap<String, SettableBeanProperty>
166+
{
167+
private static final long serialVersionUID = 1L;
168+
169+
@Override
170+
public SettableBeanProperty get(Object key0) {
171+
String key = (String) key0;
172+
return super.get(key.toLowerCase());
173+
}
174+
175+
@Override
176+
public SettableBeanProperty put(String key, SettableBeanProperty value) {
177+
key = key.toLowerCase();
178+
return super.put(key, value);
179+
}
180+
}
149181
}

0 commit comments

Comments
 (0)