10
10
import com .fasterxml .jackson .databind .DeserializationFeature ;
11
11
import com .fasterxml .jackson .databind .JsonDeserializer ;
12
12
import com .fasterxml .jackson .databind .JsonMappingException ;
13
+ import com .fasterxml .jackson .databind .MapperFeature ;
13
14
import com .fasterxml .jackson .databind .PropertyName ;
15
+ import com .fasterxml .jackson .databind .cfg .MapperConfig ;
14
16
import com .fasterxml .jackson .databind .deser .SettableBeanProperty ;
15
17
import com .fasterxml .jackson .databind .util .ClassUtil ;
16
18
import com .fasterxml .jackson .databind .util .NameTransformer ;
@@ -77,18 +79,38 @@ public class BeanPropertyMap
77
79
private final Map <String ,String > _aliasMapping ;
78
80
79
81
/**
80
- * @since 2.9
82
+ * We require {@link Locale} since case changes are locale-sensitive in certain
83
+ * cases (see <a href="https://en.wikipedia.org/wiki/Dotted_and_dotless_I">Turkish I</a>
84
+ * for example)
85
+ *
86
+ * @since 2.11
87
+ */
88
+ private final Locale _locale ;
89
+
90
+ /**
91
+ * @since 2.11
81
92
*/
82
93
public BeanPropertyMap (boolean caseInsensitive , Collection <SettableBeanProperty > props ,
83
- Map <String ,List <PropertyName >> aliasDefs )
94
+ Map <String ,List <PropertyName >> aliasDefs ,
95
+ Locale locale )
84
96
{
85
97
_caseInsensitive = caseInsensitive ;
86
98
_propsInOrder = props .toArray (new SettableBeanProperty [props .size ()]);
87
99
_aliasDefs = aliasDefs ;
88
100
_aliasMapping = _buildAliasMapping (aliasDefs );
101
+ _locale = locale ;
89
102
init (props );
90
103
}
91
104
105
+ /**
106
+ * @deprecated since 2.11
107
+ */
108
+ @ Deprecated
109
+ public BeanPropertyMap (boolean caseInsensitive , Collection <SettableBeanProperty > props ,
110
+ Map <String ,List <PropertyName >> aliasDefs ) {
111
+ this (caseInsensitive , props , aliasDefs , Locale .getDefault ());
112
+ }
113
+
92
114
/* Copy constructors used when a property can replace existing one
93
115
*
94
116
* @since 2.9.6
@@ -98,6 +120,7 @@ private BeanPropertyMap(BeanPropertyMap src,
98
120
{
99
121
// First, copy most fields as is:
100
122
_caseInsensitive = src ._caseInsensitive ;
123
+ _locale = src ._locale ;
101
124
_hashMask = src ._hashMask ;
102
125
_size = src ._size ;
103
126
_spillCount = src ._spillCount ;
@@ -120,6 +143,7 @@ private BeanPropertyMap(BeanPropertyMap src,
120
143
{
121
144
// First, copy most fields as is:
122
145
_caseInsensitive = src ._caseInsensitive ;
146
+ _locale = src ._locale ;
123
147
_hashMask = src ._hashMask ;
124
148
_size = src ._size ;
125
149
_spillCount = src ._spillCount ;
@@ -156,7 +180,8 @@ private BeanPropertyMap(BeanPropertyMap src,
156
180
@ Deprecated // since 2.8
157
181
public BeanPropertyMap (boolean caseInsensitive , Collection <SettableBeanProperty > props )
158
182
{
159
- this (caseInsensitive , props , Collections .<String ,List <PropertyName >>emptyMap ());
183
+ this (caseInsensitive , props , Collections .<String ,List <PropertyName >>emptyMap (),
184
+ Locale .getDefault ());
160
185
}
161
186
162
187
/**
@@ -165,6 +190,7 @@ public BeanPropertyMap(boolean caseInsensitive, Collection<SettableBeanProperty>
165
190
protected BeanPropertyMap (BeanPropertyMap base , boolean caseInsensitive )
166
191
{
167
192
_caseInsensitive = caseInsensitive ;
193
+ _locale = base ._locale ;
168
194
_aliasDefs = base ._aliasDefs ;
169
195
_aliasMapping = base ._aliasMapping ;
170
196
@@ -247,10 +273,22 @@ private final static int findSize(int size)
247
273
}
248
274
return result ;
249
275
}
250
-
276
+
277
+ /**
278
+ * @since 2.11
279
+ */
280
+ public static BeanPropertyMap construct (MapperConfig <?> config ,
281
+ Collection <SettableBeanProperty > props ,
282
+ Map <String ,List <PropertyName >> aliasMapping ) {
283
+ return new BeanPropertyMap (config .isEnabled (MapperFeature .ACCEPT_CASE_INSENSITIVE_PROPERTIES ),
284
+ props , aliasMapping ,
285
+ config .getLocale ());
286
+ }
287
+
251
288
/**
252
- * @since 2.6
289
+ * @deprecated since 2.11
253
290
*/
291
+ @ Deprecated
254
292
public static BeanPropertyMap construct (Collection <SettableBeanProperty > props ,
255
293
boolean caseInsensitive , Map <String ,List <PropertyName >> aliasMapping ) {
256
294
return new BeanPropertyMap (caseInsensitive , props , aliasMapping );
@@ -490,7 +528,7 @@ public SettableBeanProperty[] getPropertiesInInsertionOrder() {
490
528
// Confining this case insensitivity to this function (and the find method) in case we want to
491
529
// apply a particular locale to the lower case function. For now, using the default.
492
530
protected final String getPropertyName (SettableBeanProperty prop ) {
493
- return _caseInsensitive ? prop .getName ().toLowerCase () : prop .getName ();
531
+ return _caseInsensitive ? prop .getName ().toLowerCase (_locale ) : prop .getName ();
494
532
}
495
533
496
534
/*
@@ -521,7 +559,7 @@ public SettableBeanProperty find(String key)
521
559
throw new IllegalArgumentException ("Cannot pass null property name" );
522
560
}
523
561
if (_caseInsensitive ) {
524
- key = key .toLowerCase ();
562
+ key = key .toLowerCase (_locale );
525
563
}
526
564
527
565
// inlined `_hashCode(key)`
@@ -779,7 +817,7 @@ private Map<String,String> _buildAliasMapping(Map<String,List<PropertyName>> def
779
817
for (Map .Entry <String ,List <PropertyName >> entry : defs .entrySet ()) {
780
818
String key = entry .getKey ();
781
819
if (_caseInsensitive ) {
782
- key = key .toLowerCase ();
820
+ key = key .toLowerCase (_locale );
783
821
}
784
822
for (PropertyName pn : entry .getValue ()) {
785
823
String mapped = pn .getSimpleName ();
0 commit comments