@@ -20,26 +20,22 @@ public class BeanDeserializerBuilder
20
20
{
21
21
/*
22
22
/**********************************************************
23
- /* General information about POJO
23
+ /* Configuration
24
24
/**********************************************************
25
25
*/
26
26
27
- /**
28
- * Introspected information about POJO for deserializer to handle
29
- */
30
- final protected BeanDescription _beanDesc ;
27
+ final protected DeserializationConfig _config ;
31
28
32
- /**
33
- * Whether default setting for properties without any view annotations
34
- * is to include (true) or exclude (false).
29
+ /*
30
+ /**********************************************************
31
+ /* General information about POJO
32
+ /**********************************************************
35
33
*/
36
- final protected boolean _defaultViewInclusion ;
37
34
38
35
/**
39
- * Flag that indicates whether default settings suggest use of case-insensitive
40
- * property comparison or not.
36
+ * Introspected information about POJO for deserializer to handle
41
37
*/
42
- final protected boolean _caseInsensitivePropertyComparison ;
38
+ final protected BeanDescription _beanDesc ;
43
39
44
40
/*
45
41
/**********************************************************
@@ -114,8 +110,7 @@ public BeanDeserializerBuilder(BeanDescription beanDesc,
114
110
DeserializationConfig config )
115
111
{
116
112
_beanDesc = beanDesc ;
117
- _defaultViewInclusion = config .isEnabled (MapperFeature .DEFAULT_VIEW_INCLUSION );
118
- _caseInsensitivePropertyComparison = config .isEnabled (MapperFeature .ACCEPT_CASE_INSENSITIVE_PROPERTIES );
113
+ _config = config ;
119
114
}
120
115
121
116
/**
@@ -125,8 +120,7 @@ public BeanDeserializerBuilder(BeanDescription beanDesc,
125
120
protected BeanDeserializerBuilder (BeanDeserializerBuilder src )
126
121
{
127
122
_beanDesc = src ._beanDesc ;
128
- _defaultViewInclusion = src ._defaultViewInclusion ;
129
- _caseInsensitivePropertyComparison = src ._caseInsensitivePropertyComparison ;
123
+ _config = src ._config ;
130
124
131
125
// let's make copy of properties
132
126
_properties .putAll (src ._properties );
@@ -205,6 +199,11 @@ public void addInjectable(PropertyName propName, JavaType propType,
205
199
if (_injectables == null ) {
206
200
_injectables = new ArrayList <ValueInjector >();
207
201
}
202
+ boolean fixAccess = _config .canOverrideAccessModifiers ();
203
+ boolean forceAccess = fixAccess && _config .isEnabled (MapperFeature .OVERRIDE_PUBLIC_ACCESS_MODIFIERS );
204
+ if (fixAccess ) {
205
+ member .fixAccess (forceAccess );
206
+ }
208
207
_injectables .add (new ValueInjector (propName , propType ,
209
208
contextAnnotations , member , valueId ));
210
209
}
@@ -314,7 +313,7 @@ public AnnotatedMethod getBuildMethod() {
314
313
public JsonPOJOBuilder .Value getBuilderConfig () {
315
314
return _builderConfig ;
316
315
}
317
-
316
+
318
317
/*
319
318
/**********************************************************
320
319
/* Build method(s)
@@ -328,14 +327,16 @@ public JsonPOJOBuilder.Value getBuilderConfig() {
328
327
public JsonDeserializer <?> build ()
329
328
{
330
329
Collection <SettableBeanProperty > props = _properties .values ();
331
- BeanPropertyMap propertyMap = BeanPropertyMap .construct (props , _caseInsensitivePropertyComparison );
330
+ _fixAccess (props );
331
+
332
+ BeanPropertyMap propertyMap = BeanPropertyMap .construct (props ,
333
+ _config .isEnabled (MapperFeature .ACCEPT_CASE_INSENSITIVE_PROPERTIES ));
332
334
propertyMap .assignIndexes ();
333
335
334
336
// view processing must be enabled if:
335
337
// (a) fields are not included by default (when deserializing with view), OR
336
338
// (b) one of properties has view(s) to included in defined
337
- boolean anyViews = !_defaultViewInclusion ;
338
-
339
+ boolean anyViews = !_config .isEnabled (MapperFeature .DEFAULT_VIEW_INCLUSION );
339
340
if (!anyViews ) {
340
341
for (SettableBeanProperty prop : props ) {
341
342
if (prop .hasViews ()) {
@@ -382,8 +383,10 @@ public JsonDeserializer<?> buildBuilderBased(JavaType valueType,
382
383
if (_buildMethod == null ) {
383
384
// as per [databind#777], allow empty name
384
385
if (!expBuildMethodName .isEmpty ()) {
385
- throw new IllegalArgumentException ("Builder class " +_beanDesc .getBeanClass ().getName ()
386
- +" does not have build method (name: '" +expBuildMethodName +"')" );
386
+ throw new IllegalArgumentException (String .format (
387
+ "Builder class %s does not have build method (name: '%s')" ,
388
+ _beanDesc .getBeanClass ().getName (),
389
+ expBuildMethodName ));
387
390
}
388
391
} else {
389
392
// also: type of the method must be compatible
@@ -399,10 +402,12 @@ public JsonDeserializer<?> buildBuilderBased(JavaType valueType,
399
402
}
400
403
// And if so, we can try building the deserializer
401
404
Collection <SettableBeanProperty > props = _properties .values ();
402
- BeanPropertyMap propertyMap = BeanPropertyMap .construct (props , _caseInsensitivePropertyComparison );
405
+ _fixAccess (props );
406
+ BeanPropertyMap propertyMap = BeanPropertyMap .construct (props ,
407
+ _config .isEnabled (MapperFeature .ACCEPT_CASE_INSENSITIVE_PROPERTIES ));
403
408
propertyMap .assignIndexes ();
404
409
405
- boolean anyViews = !_defaultViewInclusion ;
410
+ boolean anyViews = !_config . isEnabled ( MapperFeature . DEFAULT_VIEW_INCLUSION ) ;
406
411
407
412
if (!anyViews ) {
408
413
for (SettableBeanProperty prop : props ) {
@@ -427,4 +432,46 @@ public JsonDeserializer<?> buildBuilderBased(JavaType valueType,
427
432
_beanDesc , propertyMap , _backRefProperties , _ignorableProps , _ignoreAllUnknown ,
428
433
anyViews );
429
434
}
435
+
436
+ /*
437
+ /**********************************************************
438
+ /* Internal helper method(s)
439
+ /**********************************************************
440
+ */
441
+
442
+ private void _fixAccess (Collection <SettableBeanProperty > mainProps )
443
+ {
444
+ /* 07-Sep-2016, tatu: Ideally we should be able to avoid forcing
445
+ * access to properties that are likely ignored, but due to
446
+ * renaming it seems this is not a safe thing to do (there was
447
+ * at least one failing test). May need to dig deeper in future;
448
+ * for now let's just play it safe.
449
+ */
450
+ /*
451
+ Set<String> ignorable = _ignorableProps;
452
+ if (ignorable == null) {
453
+ ignorable = Collections.emptySet();
454
+ }
455
+ */
456
+ for (SettableBeanProperty prop : mainProps ) {
457
+ /*
458
+ // first: no point forcing access on to-be-ignored properties
459
+ if (ignorable.contains(prop.getName())) {
460
+ continue;
461
+ }
462
+ */
463
+ prop .fixAccess (_config );
464
+ }
465
+ if (_backRefProperties != null ) {
466
+ for (SettableBeanProperty prop : _backRefProperties .values ()) {
467
+ prop .fixAccess (_config );
468
+ }
469
+ }
470
+ if (_anySetter != null ) {
471
+ _anySetter .fixAccess (_config );
472
+ }
473
+ if (_buildMethod != null ) {
474
+ _buildMethod .fixAccess (_config .isEnabled (MapperFeature .OVERRIDE_PUBLIC_ACCESS_MODIFIERS ));
475
+ }
476
+ }
430
477
}
0 commit comments