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

-- 
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/3ab8dc3e-dd1e-4e36-b4b7-8e11f2230ec4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to