jackson-databind
jackson-databind copied to clipboard
Deduction of supertypes
To discuss: Alternative implementation of #3289 allowing supertypes to be selected.
Animal {a,b} <- Cat {c} , Dog {d}
In this form it is very lenient:
- Any single valid Animal field (e.g. {a}) will resolve Animal if Animal is included in the
@JsonSubTypes
- But a non-abstract annotated root class already counts as a JsonType (I had not realised Animal was included without being explicitly redeclared in it's own
@JsonSubTypes
)
As seen from changes to the tests, it's actually fairly hard to get this code to fallback to defaultImpl
if Animal
is non-abstract. This represents a change in behaviour.
h3. FAIL_ON_UNKNOWN_PROPERTIES
Notably the code remains unaware of FAIL_ON_UNKNOWN_PROPERTIES
so {a,x}
will resolve subtype as Animal
but then fail on property x
. This is quite easy to resolve but is a policy that needs clarifying - should {a,x}
fail deduction and use defaultImpl
or deduce Animal and fail via further-downstream error handling?
I wish I could give good feedback here, but unfortunately I don't really know the area well enough. I grasp the general challenges but I feel this really needs attention from someone else to focus, in addition to @drekbour who obviously knows what he's doing. :)
Just not sure where to get that feedback; mailing lists are often black holes / void into which I can yell questions and not get many answers.
Ok. I'm still thinking on it myself but am coming around to the idea that honouring FAIL_ON_UNKNOWN_PROPERTIES
is more likely to meet user expectations. I'll add a further commit to this PR with that.
FYI This is PR is not abandoned. Additional thought : incorporate required properties