Skip to content

Add Jackson 3 annotation support - #1740

Merged
joelittlejohn merged 1 commit into
joelittlejohn:masterfrom
diegogranados:jackson3_annotator
Jan 31, 2026
Merged

Add Jackson 3 annotation support#1740
joelittlejohn merged 1 commit into
joelittlejohn:masterfrom
diegogranados:jackson3_annotator

Conversation

@diegogranados

Copy link
Copy Markdown
Contributor

The change introduces a new Jackson3 annotator, that modifies the existing Jackson-2 annotator only for annotations from jackson-databind package, that needs to be changed to the new tools.jackson package in Jackson 3.x

The default annotator continues to be Jackson 2

@unkish

unkish commented Dec 9, 2025

Copy link
Copy Markdown
Collaborator

Have you tried to build/test it locally using JDK 8 ?

@diegogranados

Copy link
Copy Markdown
Contributor Author

I just tested and build on jdk8 is broken (because of Jackson 3 classes being compiled with target level 17) . It makes sense, as Jackson 3 has raised its JDK baseline to 17 (see item 1 in Jackson 3 Migration guide ; there are links to the voting process / decision of uplifting this baseline ). There's no way for jsonschema2pojo to support Jackson 3 without also uplifting baseline jdk to 17 I think.

@diegogranados

Copy link
Copy Markdown
Contributor Author

I've just seen your work for uplifting baseline jdk to 17, great stuff! I'll rebase my PR right away

@diegogranados

Copy link
Copy Markdown
Contributor Author

Rebased it is :)

@unkish unkish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally seems like mentioning jackson3 is missing at least in following places:

  • GenerationConfig
  • README.md
  • build.gradle files in example/android/**

Comment thread jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/JacksonAnnotator.java Outdated

@Override
protected void addJsonDeserializeAnnotation(JFieldVar field) {
field.annotate(JsonDeserialize.class).param("as", LinkedHashSet.class);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the method should just return annotation class to apply ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is viable, the problem is that the JsonDeserialize annotation don't have any common ancestor in Jackson 2 / Jackson 3 (they're in different packages now). Returning the bare class forces you to deal with casts from different packages, just the kind of details that you want delegated in the subclasses

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is that the JsonDeserialize annotation don't have any common ancestor in Jackson 2 / Jackson 3

Not really a problem IMO

  1. annotations can't have any common ancestor other than implicit superinterface java.lang.annotation.Annotation
  2. JFieldVar::annotate doesn't care much if there's common ancestor or not

I don't think this is viable

Both overrides applying same logic with different argument just doesn't feel right to me.
I'll leave this "open" for someone else to express their opinion

Comment thread jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html Outdated
Comment thread jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jackson3Annotator.java Outdated
Comment thread jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/JacksonAnnotator.java Outdated
@joelittlejohn

Copy link
Copy Markdown
Owner

Great addition @diegogranados, thank you! And thanks for reviewing @unkish. Just a bit of tidying to do and we can merge.

@diegogranados

diegogranados commented Dec 24, 2025 via email

Copy link
Copy Markdown
Contributor Author

@diegogranados

Copy link
Copy Markdown
Contributor Author

Thanks a lot for the detailed review @unkish. I pushed an update

@unkish unkish left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsonschema2pojo-gradle-plugin\README.md seems to be missing mentioning of jackson3


@Override
protected void addJsonDeserializeAnnotation(JFieldVar field) {
field.annotate(JsonDeserialize.class).param("as", LinkedHashSet.class);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem is that the JsonDeserialize annotation don't have any common ancestor in Jackson 2 / Jackson 3

Not really a problem IMO

  1. annotations can't have any common ancestor other than implicit superinterface java.lang.annotation.Annotation
  2. JFieldVar::annotate doesn't care much if there's common ancestor or not

I don't think this is viable

Both overrides applying same logic with different argument just doesn't feel right to me.
I'll leave this "open" for someone else to express their opinion

@diegogranados

Copy link
Copy Markdown
Contributor Author

@unkish, I understand your proposal now for the Jackson2/3 annotator. It is implemented, I hope this is what you meant.
The missing references in the gradle plugin README.md and the format change in the license header are also fixed

Comment thread jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jackson3Annotator.java Outdated
@unkish

unkish commented Jan 16, 2026

Copy link
Copy Markdown
Collaborator

@diegogranados

Copy link
Copy Markdown
Contributor Author

@unkish The Android action is also working in my fork (I think I understand the problem: you can have one project configured with the jackson2 databind or with the jackson3 databind dependency, but not both simultaneously). I was hesitant about leaving the dependencies commented for this in jsonschema2pojo-gradle-plugin/example/android/app/build.gradle + ../lib.gradle, but at the end I preferred to leave it clean, as this is just a concrete example.

Just to learn: I tried to run the action locally before pushing doing the same preparation steps that the task does, but the gradle build was failing for me with error

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:generateJsonSchema2PojoForDebug'.
> No such property: extension for class: com.android.build.gradle.AppPlugin

Any chance you know the cause? I configured the same Android Sdk version that the action downloaded and the same Gradle version (8.9)

@joelittlejohn

Copy link
Copy Markdown
Owner

@diegogranados It looks like the Android action is working okay (see checks, I just approved these to run).

The change introduces a new Jackson3 annotator, that modifies the
existing Jackson-2 annotator only for annotations from jackson-databind
package, that needs to be changed to the new tools.jackson package
in Jackson 3.x

The default annotator continues to be Jackson 2
@joelittlejohn joelittlejohn added this to the 1.3.0 milestone Jan 31, 2026
@joelittlejohn joelittlejohn changed the title Initial Jackson-3 annotator support Add Jackson 3 annotation support Jan 31, 2026
@joelittlejohn
joelittlejohn merged commit 938dfe2 into joelittlejohn:master Jan 31, 2026
3 checks passed
@joelittlejohn

Copy link
Copy Markdown
Owner

Great work and really fantastic to have Jackson 3 support, thank you @diegogranados and @unkish!

@diegogranados

Copy link
Copy Markdown
Contributor Author

Thank you @unkish, @joelittlejohn! It has been both a joy and an honour working with you on this. Looking forward to have this released!

@joelittlejohn

Copy link
Copy Markdown
Owner

@diegogranados I think we should include more annotations in the Jackson3Annotator. I would expect that all annotations come from Jackson 3 if using the Jackson3Annotator, no?

@joelittlejohn

Copy link
Copy Markdown
Owner

Sorry, I understand more about the split between the two now after consulting the migration guide. Ignore me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants