@@ -135,6 +135,11 @@ public abstract class BeanDeserializerBase
135
135
*/
136
136
final protected Set <String > _ignorableProps ;
137
137
138
+ /**
139
+ * Keep track of the the properties that needs to be specifically included.
140
+ */
141
+ final protected Set <String > _includableProps ;
142
+
138
143
/**
139
144
* Flag that can be set to ignore and skip unknown properties.
140
145
* If set, will not throw an exception for unknown properties.
@@ -201,6 +206,7 @@ protected BeanDeserializerBase(BeanDeserializerBuilder builder,
201
206
BeanDescription beanDesc ,
202
207
BeanPropertyMap properties , Map <String , SettableBeanProperty > backRefs ,
203
208
Set <String > ignorableProps , boolean ignoreAllUnknown ,
209
+ Set <String > includableProps ,
204
210
boolean hasViews )
205
211
{
206
212
super (beanDesc .getType ());
@@ -211,6 +217,7 @@ protected BeanDeserializerBase(BeanDeserializerBuilder builder,
211
217
_backRefs = backRefs ;
212
218
_ignorableProps = ignorableProps ;
213
219
_ignoreAllUnknown = ignoreAllUnknown ;
220
+ _includableProps = includableProps ;
214
221
215
222
_anySetter = builder .getAnySetter ();
216
223
List <ValueInjector > injectables = builder .getInjectables ();
@@ -263,6 +270,7 @@ protected BeanDeserializerBase(BeanDeserializerBase src, boolean ignoreAllUnknow
263
270
_backRefs = src ._backRefs ;
264
271
_ignorableProps = src ._ignorableProps ;
265
272
_ignoreAllUnknown = ignoreAllUnknown ;
273
+ _includableProps = src ._includableProps ;
266
274
_anySetter = src ._anySetter ;
267
275
_injectables = src ._injectables ;
268
276
_objectIdReader = src ._objectIdReader ;
@@ -288,6 +296,7 @@ protected BeanDeserializerBase(BeanDeserializerBase src, NameTransformer unwrapp
288
296
_backRefs = src ._backRefs ;
289
297
_ignorableProps = src ._ignorableProps ;
290
298
_ignoreAllUnknown = (unwrapper != null ) || src ._ignoreAllUnknown ;
299
+ _includableProps = src ._includableProps ;
291
300
_anySetter = src ._anySetter ;
292
301
_injectables = src ._injectables ;
293
302
_objectIdReader = src ._objectIdReader ;
@@ -325,6 +334,7 @@ public BeanDeserializerBase(BeanDeserializerBase src, ObjectIdReader oir)
325
334
_backRefs = src ._backRefs ;
326
335
_ignorableProps = src ._ignorableProps ;
327
336
_ignoreAllUnknown = src ._ignoreAllUnknown ;
337
+ _includableProps = src ._includableProps ;
328
338
_anySetter = src ._anySetter ;
329
339
_injectables = src ._injectables ;
330
340
@@ -351,6 +361,14 @@ public BeanDeserializerBase(BeanDeserializerBase src, ObjectIdReader oir)
351
361
}
352
362
353
363
public BeanDeserializerBase (BeanDeserializerBase src , Set <String > ignorableProps )
364
+ {
365
+ this (src , ignorableProps , src ._includableProps );
366
+ }
367
+
368
+ /**
369
+ * @since 2.12
370
+ */
371
+ public BeanDeserializerBase (BeanDeserializerBase src , Set <String > ignorableProps , Set <String > includableProps )
354
372
{
355
373
super (src ._beanType );
356
374
_beanType = src ._beanType ;
@@ -362,6 +380,7 @@ public BeanDeserializerBase(BeanDeserializerBase src, Set<String> ignorableProps
362
380
_backRefs = src ._backRefs ;
363
381
_ignorableProps = ignorableProps ;
364
382
_ignoreAllUnknown = src ._ignoreAllUnknown ;
383
+ _includableProps = includableProps ;
365
384
_anySetter = src ._anySetter ;
366
385
_injectables = src ._injectables ;
367
386
@@ -375,9 +394,10 @@ public BeanDeserializerBase(BeanDeserializerBase src, Set<String> ignorableProps
375
394
376
395
// 01-May-2016, tatu: [databind#1217]: Remove properties from mapping,
377
396
// to avoid them being deserialized
378
- _beanProperties = src ._beanProperties .withoutProperties (ignorableProps );
397
+ _beanProperties = src ._beanProperties .withoutProperties (ignorableProps , includableProps );
379
398
}
380
399
400
+
381
401
/**
382
402
* @since 2.8
383
403
*/
@@ -394,6 +414,7 @@ protected BeanDeserializerBase(BeanDeserializerBase src, BeanPropertyMap beanPro
394
414
_backRefs = src ._backRefs ;
395
415
_ignorableProps = src ._ignorableProps ;
396
416
_ignoreAllUnknown = src ._ignoreAllUnknown ;
417
+ _includableProps = src ._includableProps ;
397
418
_anySetter = src ._anySetter ;
398
419
_injectables = src ._injectables ;
399
420
_objectIdReader = src ._objectIdReader ;
@@ -411,7 +432,21 @@ protected BeanDeserializerBase(BeanDeserializerBase src, BeanPropertyMap beanPro
411
432
412
433
public abstract BeanDeserializerBase withObjectIdReader (ObjectIdReader oir );
413
434
414
- public abstract BeanDeserializerBase withIgnorableProperties (Set <String > ignorableProps );
435
+ public BeanDeserializerBase withIgnorableProperties (Set <String > ignorableProps ) {
436
+ return withIgnorableProperties (ignorableProps , _includableProps );
437
+ }
438
+
439
+ /**
440
+ * @since 2.12
441
+ */
442
+ public abstract BeanDeserializerBase withIgnorableProperties (Set <String > ignorableProps , Set <String > includableProps );
443
+
444
+ /**
445
+ * @since 2.12
446
+ */
447
+ public BeanDeserializerBase withIncludableProperties (Set <String > includableProperties ) {
448
+ return withIgnorableProperties (_ignorableProps , includableProperties );
449
+ }
415
450
416
451
// NOTE! To be made `abstract` in 2.12 or later
417
452
/**
@@ -422,7 +457,7 @@ public BeanDeserializerBase withIgnoreAllUnknown(boolean ignoreUnknown) {
422
457
if (ignoreUnknown == _ignoreAllUnknown ) {
423
458
return this ;
424
459
}
425
- return withIgnorableProperties (_ignorableProps );
460
+ return withIgnorableProperties (_ignorableProps , _includableProps );
426
461
}
427
462
428
463
/**
@@ -469,10 +504,10 @@ public void resolve(DeserializationContext ctxt) throws JsonMappingException
469
504
// 22-Jan-2018, tatu: May need to propagate "ignorable" status (from `Access.READ_ONLY`
470
505
// or perhaps class-ignorables) into Creator properties too. Can not just delete,
471
506
// at this point, but is needed for further processing down the line
472
- if (_ignorableProps != null ) {
507
+ if (_ignorableProps != null || _includableProps != null ) {
473
508
for (int i = 0 , end = creatorProps .length ; i < end ; ++i ) {
474
509
SettableBeanProperty prop = creatorProps [i ];
475
- if (_ignorableProps . contains (prop .getName ())) {
510
+ if (IgnorePropertiesUtil . shouldIgnore (prop .getName (), _ignorableProps , _includableProps )) {
476
511
creatorProps [i ].markAsIgnorable ();
477
512
}
478
513
}
@@ -773,6 +808,21 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
773
808
contextual = contextual .withIgnoreAllUnknown (true );
774
809
}
775
810
}
811
+ JsonIncludeProperties .Value inclusions = intr .findPropertyInclusions (accessor );
812
+ if (inclusions != null ) {
813
+ Set <String > included = inclusions .getIncluded ();
814
+ Set <String > prev = contextual ._includableProps ;
815
+ if (prev != null && included != null ) {
816
+ Set <String > newIncluded = new HashSet <>();
817
+ // Make the intersection with the previously included properties.
818
+ for (String prop : prev ) {
819
+ if (included .contains (prop )) {
820
+ newIncluded .add (prop );
821
+ }
822
+ }
823
+ contextual = contextual .withIncludableProperties (newIncluded );
824
+ }
825
+ }
776
826
}
777
827
778
828
// One more thing: are we asked to serialize POJO as array?
@@ -1601,7 +1651,8 @@ protected void handleUnknownVanilla(JsonParser p, DeserializationContext ctxt,
1601
1651
Object beanOrBuilder , String propName )
1602
1652
throws IOException
1603
1653
{
1604
- if (_ignorableProps != null && _ignorableProps .contains (propName )) {
1654
+
1655
+ if (IgnorePropertiesUtil .shouldIgnore (propName , _ignorableProps , _includableProps )) {
1605
1656
handleIgnoredProperty (p , ctxt , beanOrBuilder , propName );
1606
1657
} else if (_anySetter != null ) {
1607
1658
try {
@@ -1629,7 +1680,7 @@ protected void handleUnknownProperty(JsonParser p, DeserializationContext ctxt,
1629
1680
p .skipChildren ();
1630
1681
return ;
1631
1682
}
1632
- if (_ignorableProps != null && _ignorableProps . contains (propName )) {
1683
+ if (IgnorePropertiesUtil . shouldIgnore (propName , _ignorableProps , _includableProps )) {
1633
1684
handleIgnoredProperty (p , ctxt , beanOrClass , propName );
1634
1685
}
1635
1686
// Otherwise use default handling (call handler(s); if not
0 commit comments