jackson-databind icon indicating copy to clipboard operation
jackson-databind copied to clipboard

Deduction of supertypes

Open drekbour opened this issue 2 years ago • 3 comments

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?

drekbour avatar Oct 11 '21 20:10 drekbour

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.

cowtowncoder avatar Oct 15 '21 22:10 cowtowncoder

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.

drekbour avatar Oct 18 '21 21:10 drekbour

FYI This is PR is not abandoned. Additional thought : incorporate required properties

drekbour avatar Jan 11 '22 16:01 drekbour