Is it possible to deserialize only fields from interface
public interface B {
String getB();
}
public interface A {
String getA();
}
public class Impl implements A, B {
@Override
public String getA() {
return "stringA";
}
@Override
public String getB() {
return "stringB";
}
public static void main(String[] args) {
ObjectMapper mapper = new ObjectMapper();
A implA = new Impl();
B implB = new Impl();
String jsonA = null;
String jsonB = null;
try {
jsonA = mapper.writeValueAsString(implA);
jsonB = mapper.writeValueAsString(implB);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
System.out.println(jsonA);
System.out.println();
System.out.println(jsonB);
}
}
What i expected was
Interface A
{"a":"stringA"}
Interface B
{"b":"stringB"}
What i get is
{"a":"stringA","b":"stringB"}
{"a":"stringA","b":"stringB"}
It is possible for one interface, with this annotation @JsonSerialize(as=A.class), but it only works for the first interface. The output with @JsonSerialize is
{"a":"stringA"}
{"a":"stringA"}