jackson-jaxrs-providers icon indicating copy to clipboard operation
jackson-jaxrs-providers copied to clipboard

Change jackson-module-jaxb-annotations dependency to optional for JSON

Open gopackgo90 opened this issue 4 years ago • 4 comments

I have com.fasterxml.jackson.jaxrs.jackson-jaxrs-json-provider 2.10.0 installed in an OSGi environment without com.fasterxml.jackson.module.jackson-module-jaxb-annotations installed since it is optional for OSGi environments. However, when I declare com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider as a dependency in my Maven project, the org.apache.felix:maven-bundle-plugin generates the Import-Package section of my MANIFEST.MF for my project's bundle as, in part:

javax.xml.bind;version="[2.3,3)",javax.xml.bind.annotation;version="[2.3,3)"

Which is a problem for me since my OSGi environment only provides javax.xml.bind 2.1.0. This prevents my bundle from starting. I can work around this by excluding com.fasterxml.jackson.module:jackson-module-jaxb-annotations in my pom:

<dependency>
    <groupId>com.fasterxml.jackson.jaxrs</groupId>
    <artifactId>jackson-jaxrs-json-provider</artifactId>
    <version>2.10.0</version>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-jaxb-annotations</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Which then causes the Import-Package part of my MANIFEST.MF to be written as:

javax.xml.bind,javax.xml.bind.annotation

which works with my OSGi environment.

An alternative to me excluding com.fasterxml.jackson.module:jackson-module-jaxb-annotations from my dependency decleration would be having com.fasterxml.jackson.module:jackson-module-jaxb-annotations marked as an optional dependency in the com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider project. When that is the case I get the same result in my Import-Package as I get when I explicitly exclude com.fasterxml.jackson.module:jackson-module-jaxb-annotations.

I'm unsure if there is a reason com.fasterxml.jackson.module.jaxb is marked as optional in the osgi section of the pom, while the com.fasterxml.jackson.module:jackson-module-jaxb-annotations dependency is not also marked as optional.

gopackgo90 avatar Apr 06 '20 18:04 gopackgo90

Ok first things first: the reason dependency to jackson-module-jaxb-annotations is not optional is because there is hard dependency to some of the types of that package in base classes (which in turn do depend on api part of JAXB, annotation definitions). There is no dependency to JAXB implementation. Original reason for this inclusion was to make use of JAXB annotations (as complementary or alternative to Jackson annotations) easier, since their use is/was wide spread.

This is rather tricky thing: on one hand, if not enabling JAXB annotation support, it is probably fine not to include JAXB annotations -- instance creation of JaxbAnnotationIntrospector is done using reflection, dynamically, and not with direct class reference via new (see JsonMapperConfigurator). But at the same time if support is enabled, users need to explicitly include JAXB annotations which may or may not happen.

And unfortunately I don't really know how to test this, or know specific users who use this functionality (esp. in OSGi containers).

This may be something best brought up on dev mailing list at:

https://groups.google.com/forum/#!forum/jackson-dev

cowtowncoder avatar Apr 21 '20 03:04 cowtowncoder

Thinking about this a bit, I think that we should remove JAXB dependency from all providers with possible exception of XML provider (since jackson-dataformat-xml does, I think, depend on it). But for backwards-compatibility reasons I suspect this can only be done for 3.x; marking as such. After getting that done, may want to consider if something similar could somehow be done with 2.x.

cowtowncoder avatar Feb 21 '21 00:02 cowtowncoder

Note to self: should implement by replacing Annotation enum (with JACKSON, JAXB values), and related introspection with much simpler configuration: MapperConfigurator can be configured explicitly with specific AnnotationIntrospector to use as replacement (if any) -- caller being responsible for wrapping combination of Jackson/JAXB introspector as well. This would nicely simplify code, and as a bonus we could likely introduce new functionality in 2.13 and possibly deprecate old mechanism in 2.13 or later. Removal of existing functionality can only be done in 3.0, regardless.

cowtowncoder avatar Feb 21 '21 03:02 cowtowncoder

Did some initial groundwork for master/3.0: no more Annotations enum indirection: now need to directly specify AnnotationIntrospector to configure mapper instance with, if any. Reasonable to consider tho if that even needs to be passed separately since users could configure mapper directly anyway.

Did not yet remove JacksonJaxb[Format]Provider subtypes and thereby could not yet remove JAXB dependency; will probably do that as the next step but first want to think it through.

cowtowncoder avatar Mar 12 '21 21:03 cowtowncoder