Skip to content

Add jackson-module-spi-subtypes module - #229

Merged
cowtowncoder merged 21 commits into
FasterXML:2.xfrom
black-06:subtype
Jan 18, 2026
Merged

Add jackson-module-spi-subtypes module#229
cowtowncoder merged 21 commits into
FasterXML:2.xfrom
black-06:subtype

Conversation

@black-06

Copy link
Copy Markdown
Contributor

Adds a module that allows subtype to be registered without annotating the parent class.

It is implemented on SPI.

See FasterXML/jackson-databind#2104

Its original version is https://github.com/black-06/jackson-modules-dynamic-subtype.

I removed the custom ServiceLoader and always use the standard library,
which means that pojo always needs a no-parameter constructor.

Comment thread pom.xml Outdated
Comment thread subtype/README.md Outdated
Comment thread subtype/README.md Outdated
Comment thread subtype/src/main/java/com/fasterxml/jackson/module/subtype/SubtypeModule.java Outdated
Comment on lines +56 to +57
if (list1.isEmpty()) return list2;
if (list2.isEmpty()) return list1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the two lists are null-safe, no need for empty checking.

Comment thread subtype/src/main/java/com/fasterxml/jackson/module/subtype/SubtypeModule.java Outdated
Comment thread subtype/src/main/java/com/fasterxml/jackson/module/subtype/SubtypeModule.java Outdated
Comment thread subtype/src/main/java/com/fasterxml/jackson/module/subtype/SubtypeModule.java Outdated
Comment thread subtype/src/main/java/com/fasterxml/jackson/module/subtype/JsonSubType.java Outdated
Comment thread subtype/src/main/java/com/fasterxml/jackson/module/subtype/JsonSubType.java Outdated
Comment thread subtype/src/main/java/com/fasterxml/jackson/module/subtype/SubtypeModule.java Outdated
@cowtowncoder cowtowncoder changed the title feat: add subtype module feat: add subtype module (2.17) Nov 16, 2023
@cowtowncoder

Copy link
Copy Markdown
Member

Quick note: due to timing, decided that I will not try to get this in Jackson 2.16 -- so will need to be re-based to 2.17.
This because there's a bit of work to be done here.

For example, I think that naming of @JsonSubType should change as the general rule is that only jackson-annotations has annotations with name starting with @Json (and for legacy reasons, some in jackson-databind).
Modules can provide annotations that start with @Jackson prefix (or anything else that makes sense).

But I need to read the PR in bit more thought to make sure my feedback is relevant.

@amricko0b

Copy link
Copy Markdown

Hello everyone!
Any updates on this one?

@cowtowncoder

Copy link
Copy Markdown
Member

I totally forgot. If this was to be added, would need to re-base/re-create against 2.x branch.

@black-06
black-06 changed the base branch from 2.16 to 2.x September 4, 2025 00:57
@black-06

black-06 commented Sep 4, 2025

Copy link
Copy Markdown
Contributor Author

I totally forgot. If this was to be added, would need to re-base/re-create against 2.x branch.

I've changed base to 2.x branch, and I checked the comments above, most of them have been modified, and the problems that haven't been solved include:

  • findSubtypes: It's almost a copy of AnnotationIntrospectorPair.findSubtypes, so I tend not to modify it.
  • annotation name JsonSubType: If the user understands JsonSubTypes, then he should be able to understand JsonSubType easily, but if there is a more appropriate name, I have no problem.

Because it's been a while. We can review the code again.

Comment thread subtype/src/main/java/com/fasterxml/jackson/module/subtype/SubtypeModule.java Outdated
Comment thread subtype/src/main/java/com/fasterxml/jackson/module/subtype/SubtypeModule.java Outdated
Comment thread subtype/src/main/resources/META-INF/LICENSE Outdated
@cowtowncoder cowtowncoder added 2.20 and removed 2.17 labels Oct 31, 2025
@cowtowncoder

cowtowncoder commented Jan 12, 2026

Copy link
Copy Markdown
Member

This seems to fail on Java 8: if we are targeting Jackson 2.x, module should be Java 8 compatible.

But looks like simple change to pom.xml solves that. I'll fix it.

EDIT: done

Comment thread subtype/pom.xml Outdated
@cowtowncoder

Copy link
Copy Markdown
Member

@black-06 Ok: I have some minor questions, but overall the only changes I do require are to naming:

  1. Annotation name to avoid "@JSON" prefix: my proposal is "@JacksonSubType"
  2. Module name: jackson-module-spi-subtypes (not just "jackson-module-subtype")
  3. Module directory: spi-subtypes (not just "subtypes")

and matching changes to module-info.java and README (aside from obvious Java classes and pom.xml).
I am open to other names too, but want them to be slightly more specific.

Once naming is changed, I can get this merge in 2.x for inclusion in upcoming 2.21.0 release.

@cowtowncoder cowtowncoder added 2.21 cla-needed PR looks good (although may also require code review), but CLA needed from submitter and removed 2.20 labels Jan 12, 2026
@cowtowncoder

Copy link
Copy Markdown
Member

@black-06 One other (hopefully last) thing: if you haven't yet sent CLA (I don't think so but just in case), we would need it from:

https://github.com/FasterXML/jackson/blob/main/contributor-agreement.pdf

This only needs to be done once, before merging the first PR: one is valid for all future contributions.
The usual way is to print it, fill & sign, scan/photo, email to cla at fasterxml dot com.
Once we have it, merging can occur (assuming code review etc complete).

Looking forward to getting this PR merged; thank you again for providing it!

@black-06

Copy link
Copy Markdown
Contributor Author

@black-06 Ok: I have some minor questions, but overall the only changes I do require are to naming:

  1. Annotation name to avoid "@JSON" prefix: my proposal is "@JacksonSubType"
  2. Module name: jackson-module-spi-subtypes (not just "jackson-module-subtype")
  3. Module directory: spi-subtypes (not just "subtypes")

and matching changes to module-info.java and README (aside from obvious Java classes and pom.xml). I am open to other names too, but want them to be slightly more specific.

Once naming is changed, I can get this merge in 2.x for inclusion in upcoming 2.21.0 release.

The name has been changed. In addition,

  1. rename package to com.fasterxml.jackson.module.spisubtypes.
  2. rename SubtypeModule to SubtypesModule, SubtypeAnnotationIntrospector to SubtypesAnnotationIntrospector.

Thank you very much for your review, ps. CLA has been sent.

@black-06 black-06 changed the title feat: add subtype module (2.21) feat: add spi-subtypes module (2.21) Jan 16, 2026
@cowtowncoder cowtowncoder added cla-received PR already covered by CLA (optional label) and removed cla-needed PR looks good (although may also require code review), but CLA needed from submitter labels Jan 16, 2026
@cowtowncoder

Copy link
Copy Markdown
Member

@black-06 Thank you for doing all of that. I am hoping to go over PR one more time, get it merged, and soon prepare for 2.21.0 release that includes the new module!

@cowtowncoder cowtowncoder changed the title feat: add spi-subtypes module (2.21) Add jackson-module-spi-subtypes module Jan 18, 2026
@cowtowncoder
cowtowncoder merged commit 3cfe4bf into FasterXML:2.x Jan 18, 2026
4 checks passed
cowtowncoder added a commit that referenced this pull request Jan 18, 2026
cowtowncoder added a commit that referenced this pull request Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.21 cla-received PR already covered by CLA (optional label)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants