On Mon, Aug 12, 2019 at 5:56 PM Pablo Pazos <[email protected]> wrote:
>
> Hi,
>
> I have a model where some class attributes are concrete/final and other are 
> generic, I want to avoid adding the @type to the concrete/final. Here is an 
> example:
>
> class Action {
>
>    DvTime time;
> }
>
> class Element {
>
>    Object value;
> }
>
> final class DvTime {
>
>   ...
> }
>
> We could do:
>
> Element e = new Element();
> e.setValue(new DvTime(...));
>
> Action a = new Action();
> a.setTime(new DvTime(...));
>
>
> When those objects are serialized, I need:
>
> {
>   @type: Element,
>   value: {
>     @type: DvTime,
>     ...
>   }
> }
>
> {
>   @type: Action,
>   time: {
>     ...
>   }
> }
>
> That avoids adding the @type = DvTime for action.time because by the model I 
> know that always be a DvTime.
>
> Is that possible? Thanks!

I think the example is missing information to fully understand
relationship between types, but in general, polymorphic type handling
is optional and only used for classes with `@JsonTypeInfo` in base
class, or annotation on property. So you can select which type
hierarchies will use type ids.

Second thing is that for deserialization, one can omit "type id" if
(but only if!) there is property `defaultImpl` for `@JsonTypeInfo`. So
that could be pointing to final implementation.
There is no matching setting (yet) to prevent outputting of type id
when polymorphic types are enabled. There is an issue to support it,
and maybe it gets eventually implemented.

Those are the existing mechanisms for selective use of type ids. But
in general types are not meant to use mix-and-match approach as that
is very difficult to support on deserialization side.

-+ 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/CAL4a10j-ZkYJOpwJFAT%3DrKncM94hW8nL8qL8iaa-E51JsJ0e3Q%40mail.gmail.com.

Reply via email to