-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for JAXB's @XmlSeeAlso
(maybe similar to @JsonSubTypes
) to improve JAXB compatibility
#195
Comments
This is indeed necessary, and what can be supported will be more convenient! |
@XmlSeeAlso
(maybe similar to @JsonSubTypes
) to improve JAXB compatibility
@wanjidong This is one of things where contributions (PR) would be most welcome. I will add a note on how this might be supportable relatively easily. |
@raphw I may be overlooking something, but would this work if
and so making This alone would not work without base type having necessary annotation to induce One thing that JAXB annotations module does not and cannot do is add actual handling of annotations; the general limitation is that functionality of |
I did not manage to make that work as I needed to add XML xsi info. I ended up implementing a custom module, but it feels rather hacky: https://github.com/raphw/jackson-jaxb-extension |
Ok looks like basic support for But Jackson 2.17 will actually add support for handling
will work somewhat as expected (with XML module). |
Problem description
Jackson's XML annotation handler does not currently process the
XmlSeeAlso
of the JAXB specification. As a result, it is always possible to serialize objects based on JAXB, but it is not possible to deserialize them in all cases. This problem occurs for example if JAXB objects are created by the XJC tool from XSD files that include subtyping.For example, the following class structure represents a valid JAXB object representation:
If
base
is set toFirst
, JAXB will declare a property in the XML-instance namespace which allows to serialize and to deserialize any input as the type information is retained.Currently, Jackson discards the type information and neither processes it by resolving against
XmlSeeAlso
if it was available. If the same object was marshalled to JSON, it would result in the following JSON:{"element": {}}
which cannot be marshalled to an object and where the necessary information to unmarshall this object is neither retained.
Suggested solution
Jackson should introduce a pseudo-attribute to retain type information to support the same form of type discovery. The created JSON should add the JAXB-type within an annotation as in:
where the client should process this information when unmarshalling to recover the instance type.
I tried an implementation of such support, without knowing if this is the most efficient implementation. Also, I discovered that my solution created a
null
instance for an emptyelement
object as in the example what I worked around. If there is a better solution to that corner-case, I'd appreciate any feedback. I am happy to offer my time to integrate this into the official JAXB support if this is a desired extension.The text was updated successfully, but these errors were encountered: