Ich habe ein Objekt A mit einigen Methoden ma, mb, mc und dieses Objekt implementiert eine Schnittstelle B mit nur ma und mb.Jackson serialisiert nur Interface-Methoden
Als ich B serialisiert erwarte ich nur ma und mb als Json Antwort, aber ich bekomme auch mc.
Ich möchte dieses Verhalten automatisieren, damit alle Klassen, die ich serialisiere, serialisiert werden, basierend auf der Schnittstelle und nicht auf der Implementierung.
Wie soll ich das tun?
Beispiel:
public interface Interf {
public boolean isNo();
public int getCountI();
public long getLonGuis();
}
Umsetzung:
public class Impl implements Interf {
private final String patata = "Patata";
private final Integer count = 231321;
private final Boolean yes = true;
private final boolean no = false;
private final int countI = 23;
private final long lonGuis = 4324523423423423432L;
public String getPatata() {
return patata;
}
public Integer getCount() {
return count;
}
public Boolean getYes() {
return yes;
}
public boolean isNo() {
return no;
}
public int getCountI() {
return countI;
}
public long getLonGuis() {
return lonGuis;
}
}
Serialisierung:
ObjectMapper mapper = new ObjectMapper();
Interf interf = new Impl();
String str = mapper.writeValueAsString(interf);
System.out.println(str);
Antwort:
{
"patata": "Patata",
"count": 231321,
"yes": true,
"no": false,
"countI": 23,
"lonGuis": 4324523423423423500
}
Erwartete Antwort:
{
"no": false,
"countI": 23,
"lonGuis": 4324523423423423500
}
ähnliches Problem: [http://stackoverflow.com/questions/8922309/serialize-class-based-on-one-interface-it-implements-with-jackson-or-gson][1] [1]: http://stackoverflow.com/questions/8922309/serialize-class-based-on-one-interface-it-implements-with-jackson-or-gson – Farid