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

Discover Subclasses of a sealed class automatically #240

Merged
merged 1 commit into from
Aug 1, 2019

Conversation

shartte
Copy link
Contributor

@shartte shartte commented Jul 24, 2019

As proposed in #239, this implements automatic detection of sealed class subtypes.

I don't know how important it would be to cache this result. As far as I understand it, the ObjectMapper instance will cache it internally, but someone with more insight into Jackson's internal might need to comment.

making it possible to omit the @JsonSubTypes annotation.
@cowtowncoder
Copy link
Member

You are absolutely correct wrt caching: AnnotationIntrospector needs not (and in general then, should not) cache results, results are (indirectly) cached as subtype resolvers keep mapping calculated.

Code looks pretty clean to me (although I'd defer to @apatrida or others with kotlin-fu). The only minor question I have is that of whether it is ever the case that someone might NOT want this auto-discovery.
Does not seem likely but I am often surprised by kinds of things someone somewhere relies on.

@cowtowncoder
Copy link
Member

Ok, I assume this is fine. I am not sure if there are any problems if there are further sub-classes (sounds like sub-classes may have further sub-classes), but assume there are no issues.

@cowtowncoder cowtowncoder merged commit d5d7652 into FasterXML:2.10 Aug 1, 2019
@cowtowncoder cowtowncoder added this to the 2.10.0.pr2 milestone Aug 1, 2019
Nthalk added a commit to Nthalk/typescript-generator that referenced this pull request Jan 17, 2023
Java language level 17 and above supports isSealed on member types.

This uses the proposal of FasterXML/jackson-module-kotlin#239 and the general solution of FasterXML/jackson-module-kotlin#240 to import subtypes of a sealed object or interface that are annotated with `@JsonTypeName` and assignable to the container class or interface to create a much less verbose method of generating tagged unions.
Nthalk added a commit to Nthalk/typescript-generator that referenced this pull request Jan 17, 2023
This uses the proposal of FasterXML/jackson-module-kotlin#239 and the general solution of FasterXML/jackson-module-kotlin#240 to import subtypes of a sealed object or interface that are annotated with `@JsonTypeName` and assignable to the container class or interface to create a much less verbose method of generating tagged unions.

Sealed types are supported in kotlin 1.6+ and Java 17+, however, we don't really need the sealed functionality, as we are an offline, one-shot generator, this may work to generate the correct type mappings, but fail to parse on the runtime object mapper side unless the user is using the supported kotlin and java versions.
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.

None yet

2 participants