Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.fasterxml.jackson.annotation.JsonSubTypes;
- import com.fasterxml.jackson.annotation.JsonTypeInfo;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.fasterxml.jackson.databind.SerializationFeature;
- public class Test {
- @JsonTypeInfo( use=JsonTypeInfo.Id.CLASS)
- @JsonSubTypes({ @JsonSubTypes.Type(value = ConcreteA.class)})
- public static interface A {
- }
- public static class ConcreteA implements A {
- }
- @JsonTypeInfo( use=JsonTypeInfo.Id.CLASS)
- @JsonSubTypes({ @JsonSubTypes.Type(value = ConcreteB.class)})
- public static interface B {
- }
- public static class ConcreteB implements B {
- A a;
- public A getA() {
- return a=new ConcreteA();
- }
- }
- @org.junit.Test
- public void testSerialisation() throws JsonProcessingException {
- ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
- System.out.println(objectMapper.writeValueAsString(new ConcreteB()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement