Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Duplicate
-
Affects Version/s: 1.9.3
-
Fix Version/s: None
-
Component/s: Serializer
-
Labels:None
-
Environment:Linux, Spring /Java
-
Number of attachments :
Description
When serializing an object using an Interface,it serializes using the actual class rather interface. For ex: Interface I1 has getXX method. Class C1 implements I1 and has few other get methods. In the class where I want to serialize, I specify as below.
ObjectWriter objectWriter = new ObjectMapper().writerWithType(new TypeReference<List<I1>>(){});
And then I create a list with I1 as type and add objects of C1 to it.
List<I1> list = new ArrayList<I1>(); list.add(new C1());
Then specify
objectWriter.writeValueAsString(list).
In the output, I see that other getXX methods of C1 being serialized.On I1, I have also specified @JsonDeserialize(as=C1.class)
@JsonSerialize(as=I1.class) and on C1 I specified
@JsonSerialize(as=I1.class, typing=JsonSerialize.Typing.STATIC)
editing layout for readability