@@ -31,20 +31,22 @@ public class AnnotationBasedIntrospector
31
31
* Visibility settings to use for auto-detecting accessors.
32
32
*/
33
33
protected final JsonAutoDetect .Value _visibility ;
34
-
34
+
35
35
// // // State (collected properties, related)
36
-
36
+
37
37
protected final Map <String , APropBuilder > _props = new HashMap <String , APropBuilder >();
38
38
39
39
// // // State only for deserialization:
40
40
41
41
protected Set <String > _ignorableNames ;
42
+ protected int _features ;
42
43
43
44
protected AnnotationBasedIntrospector (Class <?> type , boolean serialization ,
44
- JsonAutoDetect .Value visibility ) {
45
+ JsonAutoDetect .Value visibility , int features ) {
45
46
_type = type ;
46
47
_forSerialization = serialization ;
47
48
_ignorableNames = serialization ? null : new HashSet <String >();
49
+ _features = features ;
48
50
49
51
// First things first: find possible `@JsonAutoDetect` to override
50
52
// default visibility settings
@@ -58,13 +60,13 @@ protected AnnotationBasedIntrospector(Class<?> type, boolean serialization,
58
60
59
61
public static POJODefinition pojoDefinitionForDeserialization (JSONReader r ,
60
62
Class <?> pojoType , JsonAutoDetect .Value visibility ) {
61
- return new AnnotationBasedIntrospector (pojoType , false , visibility )
63
+ return new AnnotationBasedIntrospector (pojoType , false , visibility , r . features () )
62
64
.introspectDefinition ();
63
65
}
64
66
65
67
public static POJODefinition pojoDefinitionForSerialization (JSONWriter w ,
66
68
Class <?> pojoType , JsonAutoDetect .Value visibility ) {
67
- return new AnnotationBasedIntrospector (pojoType , true , visibility )
69
+ return new AnnotationBasedIntrospector (pojoType , true , visibility , w . features () )
68
70
.introspectDefinition ();
69
71
}
70
72
@@ -235,9 +237,9 @@ protected void _findFields(final Class<?> currType)
235
237
236
238
// then get fields from within class itself
237
239
for (Field f : currType .getDeclaredFields ()) {
238
- // Does not include static fields, but there are couple of things we do
239
- // not include regardless:
240
- if ( f .isEnumConstant () || f .isSynthetic ()) {
240
+ // skip static fields and synthetic fields except for enum constants
241
+ if (( JSON . Feature . INCLUDE_STATIC_FIELDS . isDisabled ( _features ) && Modifier . isStatic ( f . getModifiers ())
242
+ && ! f .isEnumConstant () ) || f .isSynthetic ()) {
241
243
continue ;
242
244
}
243
245
// otherwise, first things first; explicit ignoral?
@@ -284,7 +286,7 @@ protected void _findMethods(final Class<?> currType)
284
286
final int flags = m .getModifiers ();
285
287
// 13-Jun-2015, tatu: Skip synthetic, bridge methods altogether, for now
286
288
// at least (add more complex handling only if absolutely necessary)
287
- if (Modifier .isStatic (flags )
289
+ if (( JSON . Feature . INCLUDE_STATIC_FIELDS . isDisabled ( _features ) && Modifier .isStatic (flags ) )
288
290
|| m .isSynthetic () || m .isBridge ()) {
289
291
continue ;
290
292
}
@@ -350,7 +352,7 @@ protected void _checkGetterMethod(Method m)
350
352
acc = APropAccessor .createVisible (implName , m );
351
353
} else {
352
354
acc = APropAccessor .createExplicit (explName , m );
353
- }
355
+ }
354
356
}
355
357
}
356
358
_propBuilder (implName ).getter = acc ;
@@ -397,7 +399,7 @@ protected void _checkSetterMethod(Method m)
397
399
acc = APropAccessor .createVisible (implName , m );
398
400
} else {
399
401
acc = APropAccessor .createExplicit (explName , m );
400
- }
402
+ }
401
403
}
402
404
}
403
405
_propBuilder (implName ).setter = acc ;
@@ -410,9 +412,10 @@ protected void _checkSetterMethod(Method m)
410
412
*/
411
413
412
414
protected boolean _isFieldVisible (Field f ) {
413
- // Consider transient to be non-visible
415
+ // Consider transient and static-final to be non-visible
414
416
// TODO: (maybe?) final
415
- return !Modifier .isTransient (f .getModifiers ())
417
+ return !(Modifier .isFinal (f .getModifiers ()) && Modifier .isStatic (f .getModifiers ()))
418
+ && !Modifier .isTransient (f .getModifiers ())
416
419
&& _visibility .getFieldVisibility ().isVisible (f );
417
420
}
418
421
@@ -426,7 +429,7 @@ protected boolean _isGetterVisible(Method m, boolean isIsGetter) {
426
429
protected boolean _isSetterVisible (Method m ) {
427
430
return _visibility .getSetterVisibility ().isVisible (m );
428
431
}
429
-
432
+
430
433
/*
431
434
/**********************************************************************
432
435
/* Internal methods, annotation introspection
@@ -449,7 +452,7 @@ protected String _findExplicitName(AnnotatedElement m) {
449
452
* Lookup method for finding possible annotated order of property names
450
453
* for the type this introspector is to introspect
451
454
*
452
- * @return List of property names that defines order (possibly partial); if
455
+ * @return List of property names that defines order (possibly partial); if
453
456
* none, empty List (but never null)
454
457
*/
455
458
protected List <String > _findNameSortOrder () {
@@ -465,7 +468,7 @@ protected List<String> _findNameSortOrder() {
465
468
* for the type this introspector is to introspect that should be ignored
466
469
* (both for serialization and deserialization).
467
470
*
468
- * @return List of property names that defines order (possibly partial); if
471
+ * @return List of property names that defines order (possibly partial); if
469
472
* none, empty List (but never null)
470
473
*/
471
474
protected Collection <String > _findIgnorableNames () {
@@ -480,13 +483,13 @@ protected Collection<String> _findIgnorableNames() {
480
483
protected <ANN extends Annotation > ANN _find (AnnotatedElement elem , Class <ANN > annotationType ) {
481
484
return elem .getAnnotation (annotationType );
482
485
}
483
-
486
+
484
487
/*
485
488
/**********************************************************************
486
489
/* Internal methods, other
487
490
/**********************************************************************
488
491
*/
489
-
492
+
490
493
protected APropBuilder _propBuilder (String name ) {
491
494
APropBuilder b = _props .get (name );
492
495
if (b == null ) {
@@ -546,7 +549,7 @@ protected static String _decap(String name) {
546
549
/* Helper classes
547
550
/**********************************************************************
548
551
*/
549
-
552
+
550
553
protected static class APropBuilder
551
554
implements Comparable <APropBuilder >
552
555
{
@@ -615,7 +618,7 @@ private static <A extends AccessibleObject> APropAccessor<A> _merge(APropAccesso
615
618
// should be fine to take first one
616
619
return a1 ;
617
620
}
618
-
621
+
619
622
public APropBuilder withName (String newName ) {
620
623
APropBuilder newB = new APropBuilder (this , newName );
621
624
newB .field = field ;
@@ -676,7 +679,7 @@ private static Set<String> _collectAliases(APropAccessor<?> acc, Set<String> col
676
679
}
677
680
return collectedAliases ;
678
681
}
679
-
682
+
680
683
private String _firstExplicit (APropAccessor <?> acc1 ,
681
684
APropAccessor <?> acc2 ,
682
685
APropAccessor <?> acc3 ) {
0 commit comments