Behaviour of JsonAutoDetect with Mixins #4657
Replies: 1 comment
-
I am not sure why this would be considered leakage -- intent of mix-ins is to provide annotations. So why would it by surprising annotations was indeed used? Put another way, why would mix-in have As to But I feel I am missing something here, wrt intended usage. |
Beta Was this translation helpful? Give feedback.
-
When having the following classes:
Serializing
SomeClass
withSomeMixin
as mixin, results in both fieldsa
andb
being serialized. This is becauseAUTO_DETECT_FIELDS
is enabled by default, which also discovers the fields onSomeClass
. When disablingAUTO_DETECT_FIELDS
the mixin works as expected, as long asa
is annotated withJsonProperty
:Result:
I was however surprised to see that when
SomeMixin
is annotated withJsonAutoDetect(fieldVisibility = PUBLIC_ONLY)
, both fields are serialised again. From the documentation of Mixins it became clear that all annotations from the mixin are copied to the target, thus including theJsonAutoDetect
annotation. I understand that decision but its somewhat also counter intuitive that an annotation on a mixin can leak fields from a target unintentionally:Result:
Now I was wondering whether existing API's exist to tweak this behaviour? Perhaps its possible through an
AnnotationIntrospector
to ignore theJsonAutoDetect
annotation inherited through mixins?(Fields used as example here, the same behaviour obviously exists for getters and setters too)
Beta Was this translation helpful? Give feedback.
All reactions