8
8
9
9
import com .fasterxml .jackson .databind .DeserializationContext ;
10
10
import com .fasterxml .jackson .databind .JsonMappingException ;
11
+ import com .fasterxml .jackson .databind .MapperFeature ;
11
12
import com .fasterxml .jackson .databind .deser .SettableBeanProperty ;
12
13
import com .fasterxml .jackson .databind .deser .ValueInstantiator ;
13
14
21
22
*/
22
23
public final class PropertyBasedCreator
23
24
{
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
+ */
24
35
protected final ValueInstantiator _valueInstantiator ;
25
-
36
+
26
37
/**
27
38
* Map that contains property objects for either constructor or factory
28
39
* method (whichever one is null: one property for each
29
40
* parameter for that one), keyed by logical property name
30
41
*/
31
42
protected final HashMap <String , SettableBeanProperty > _propertyLookup ;
32
43
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
-
39
44
/**
40
45
* Array that contains properties that expect value to inject, if any;
41
46
* null if no injectable values are expected.
42
47
*/
43
48
protected final SettableBeanProperty [] _allProperties ;
44
-
49
+
45
50
/*
46
51
/**********************************************************
47
52
/* Construction, initialization
48
53
/**********************************************************
49
54
*/
50
-
55
+
51
56
protected PropertyBasedCreator (ValueInstantiator valueInstantiator ,
52
- SettableBeanProperty [] creatorProps )
57
+ SettableBeanProperty [] creatorProps ,
58
+ boolean caseInsensitive )
53
59
{
54
60
_valueInstantiator = valueInstantiator ;
55
- _propertyLookup = new HashMap <String , SettableBeanProperty >();
61
+ if (caseInsensitive ) {
62
+ _propertyLookup = new CaseInsensitiveMap ();
63
+ } else {
64
+ _propertyLookup = new HashMap <String , SettableBeanProperty >();
65
+ }
56
66
final int len = creatorProps .length ;
57
67
_propertyCount = len ;
58
68
_allProperties = new SettableBeanProperty [len ];
@@ -79,24 +89,17 @@ public static PropertyBasedCreator construct(DeserializationContext ctxt,
79
89
prop = prop .withValueDeserializer (ctxt .findContextualValueDeserializer (prop .getType (), prop ));
80
90
}
81
91
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 ));
84
95
}
85
96
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
-
94
97
/*
95
98
/**********************************************************
96
99
/* Accessors
97
100
/**********************************************************
98
101
*/
99
-
102
+
100
103
public Collection <SettableBeanProperty > properties () {
101
104
return _propertyLookup .values ();
102
105
}
@@ -113,7 +116,7 @@ public SettableBeanProperty findCreatorProperty(int propertyIndex) {
113
116
}
114
117
return null ;
115
118
}
116
-
119
+
117
120
/*
118
121
/**********************************************************
119
122
/* Building process
@@ -146,4 +149,33 @@ public Object build(DeserializationContext ctxt, PropertyValueBuffer buffer) thr
146
149
}
147
150
return bean ;
148
151
}
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
+ }
149
181
}
0 commit comments