On Sat, Jul 6, 2019 at 1:20 AM Konstantin Klimov <[email protected]> wrote:
>
> Dear jackson community,
>
> I'm trying to use @JsonTypeInfo  and @JsonSubTypes I in a mixin to create 
> polymorphic type mapping for third-party classes. But it looks like the 
> annotations do not work with mixin. Could anybody please drop a hint how to 
> deal with it or find a workaround?
>
>
> class Animal { }
>
> class Cat extends Animal { }
>
> @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
> @JsonSubTypes({@JsonSubTypes.Type(value = Cat.class, name = "cat")})
> abstract class SubTypesMixin { }
>
>
> @Test
> public void mixinsShouldWorkWithSubtypesAnnotations() throws IOException {
>   // given
>   String json = "{\"type\":\"cat\"}";
>   ObjectMapper objectMapper = new ObjectMapper();
>   objectMapper.addMixIn(Animal.class, SubTypesMixin.class);
>
>   // when
>   Animal animal = new ObjectMapper()
>       .readerFor(Animal.class)
>       .readValue(json);
>
>   // then
>   assertEquals(animal.getClass(), Cat.class);
> }
>
>
> Thank you in advance,
> Regards

I see this was files as

https://github.com/FasterXML/jackson-databind/issues/2379

and the comment there is that I think your code has flaw -- you are
configuring an `ObjectMapper` correctly, but then for some reason
using a fresh new unconfigured one for operation. That would explain
the problem?

-+ 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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jackson-user/CAL4a10iSROzC0g9m8s%3DV7GGU8-uEJgUQmhRJj%3DHQcS5PGe%3DzUA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to