-
Notifications
You must be signed in to change notification settings - Fork 175
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
Auto-detect sealed classes (similar to @JsonSubTypes
)
#239
Comments
I don't know of feasibility on Kotlin module side, but since discovery of subtypes (usually based on |
@cowtowncoder I've opened a PR that implements this, including a test for both implicit and explicit specification of subtypes. |
Now that was quick! |
@JsonSubTypes
)
It`s too bad we have to write the subtype name twice when the property name is the same os the object name. This is what I have to do:
Shouldn't be a way to use the exactly class name (without leading points and outer types) as in |
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.
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.
I am not sure whether this is actually possible given Jacksons API, but I'd like to avoid having to specify the
@JsonSubTypes
annotation when working with polymorphic sealed classes.Here's an example that'll work with the current module:
But here's how I'd like it to look:
This should be possible given that Kotlin exposes the sealed class's subclasses as
Either::class.sealedSubclasses
.And here's a test function:
The text was updated successfully, but these errors were encountered: