I have a the class structure as below:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(name = "testA", value = TestA.class),
@JsonSubTypes.Type(name = "testB", value = TestB.class),
@JsonSubTypes.Type(name = "testC", value = TestC.class)
})
public abstract class Test {
}
public class TestA extends Test {
private String firstName;
private String secondName;
private String surName;
}
public class TestB extends Test {
private String adressLine1;
private String adressLine2;
private String adressLine3;
}
public class TestC extends Test {
private String hobby1;
private String hobby2;
private String hobby3;
}
The above classes are serialized into array of json elements, but when I de-serialise them back, i want the structure as below:
public class FlatStructure {
private TestA testA;
private TestB testB;
private TestC testC;
public void setTestA(TestA testA){
this.testA = testA;
}
public TestA getTestA(){
return testA;
}
.....getter and setter for testB and testC...
}
is it possible to convert the array of elements of type testA, testB and testC to properties of FlatStructure class?