On Sat, Jul 2, 2022 at 3:05 PM Pierre <[email protected]> wrote:
>
> Hello,
>
> What is the equivalent of @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include 
> = JsonTypeInfo.As.PROPERTY) in the ObjectMapper without using annotations (or 
> mixins) ?
>
> I'm looking for something like 
> ObjectMapper().registerTypeInfo(MyBaseClass::class, Id.CLASS, As.PROPERTY)
>
> Also, I don't want to activateDefaultTyping(), I just want typing for class I 
> specified (like @JsonTypeInfo behavior)

There is nothing else that I know of, specifically, although you can
probably achieve this by sub-classing `JacksonAnnotationIntrospector`
(or implementing `AnnotationIntrospector`), and defining/overriding
method that looks for `@JsonTypeInfo`.

But I think the `activateDefaultTyping()` route would make most sense:
you would need to specific custom applicability, but otherwise.

Also note that the use of `As.PROPERTY` is discouraged for polymorphic
handling: for types that do not serialize as JSON Objects it must use
`As.WRAPPER_ARRAY` logic anyway. So it is usually better to use either
`As.WRAPPER_ARRAY` or `As.WRAPPER_OBJECT`.
Technically you can of course try `As.PROPERTY` and perhaps it works
for your case; this is just a warning that it may be problematic.

-+ Tatu +-

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/CAL4a10h4nKFGnO2yEVq7dToMumUMf9BpPaBst8t2FYDBfEki7w%40mail.gmail.com.

Reply via email to