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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When having the following classes:
Serializing
SomeClasswithSomeMixinas mixin, results in both fieldsaandbbeing serialized. This is becauseAUTO_DETECT_FIELDSis enabled by default, which also discovers the fields onSomeClass. When disablingAUTO_DETECT_FIELDSthe mixin works as expected, as long asais annotated withJsonProperty:Result:
{"a":"a"}I was however surprised to see that when
SomeMixinis 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 theJsonAutoDetectannotation. I understand that decision but its somewhat also counter intuitive that an annotation on a mixin can leak fields from a target unintentionally:Result:
{"a":"a","b":"b"}Now I was wondering whether existing API's exist to tweak this behaviour? Perhaps its possible through an
AnnotationIntrospectorto ignore theJsonAutoDetectannotation 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