FasterXML / jackson-modules-base

Uber-project for foundational modules of Jackson that build directly on core components but nothing else; not including data format or datatype modules
Apache License 2.0
167 stars 77 forks source link

`JaxbAnnotationIntrospector` should honor the package level annotation `@XmlSchema` #218

Closed iiliev2 closed 1 year ago

iiliev2 commented 1 year ago

https://github.com/FasterXML/jackson-modules-base/blame/758b7004e63b5600853143b0d5586911e50b2dbf/jaxb/src/main/java/com/fasterxml/jackson/module/jaxb/JaxbAnnotationIntrospector.java#L221

Even though it is a root element, it might have a default namespaced defined at the package level. JAXB would serialize such root elements with a namespace, even if the @XmlRootElement annotation does not specify a namespace.

See also https://stackoverflow.com/questions/17789157/xjc-doesnt-generate-the-xmlelement-with-namespace

cowtowncoder commented 1 year ago

Jackson does not support use of package-level annotations with its annotation support (does not compose well with inheritance-based handling), so this is a fundamental limitation. What is supported is essentially mapping of JAXB annotations into handling Jackson does support.

So this is not and will not be supported.

iiliev2 commented 1 year ago

Jackson does not support use of package-level annotations So this is not and will not be supported.

This issue is about one particular behavior in the serializer. How would that be incompatible with the inheritance-based handling? What does that mean?

This makes me doubt the usefulness of this module. Often old projects would start schema-first and the annotated classes(and packages) would be auto generated, so they can't be modified by hand. Even if they start code-first, it would defeat the purpose of this module if one would still have to fiddle with the annotations in order to make them produce the same output as with JAXB.

At the very least, these limitations should be documented in more detail.

cowtowncoder commented 1 year ago

PRs welcome for doc changes too.

But the main thing to keep in mind is that Jackson is not -- and never meant to be or advertised as -- a JAXB implementation. It allows annotation-level interoperability that allows translating simple cases like property renaming. But it does not try to emulate semantics in cases where they differ (often due to JAXB. being XML-specific and Jackson JSON-centric).