Skip to content
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

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

Open
gopackgo90 opened this issue Apr 6, 2020 · 4 comments
Open
Labels
3.x For Jackson 3.x features, fixes

Comments

@gopackgo90
Copy link

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.

@cowtowncoder
Copy link
Member

cowtowncoder commented Apr 21, 2020

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 cowtowncoder added the 3.x For Jackson 3.x features, fixes label Feb 21, 2021
@cowtowncoder
Copy link
Member

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
Copy link
Member

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 added a commit that referenced this issue Mar 12, 2021
…tionIntrospector` directly.

Does not yet remove JAXB dependency (leaving JAXB-provider subtypes in place for now).
@cowtowncoder
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x For Jackson 3.x features, fixes
Projects
None yet
Development

No branches or pull requests

2 participants