I know how to serialize java objects. but what if I have an objects and inside another object that is null?
e.g.
My 1st class:
public class Invoice {
private Adresse adresse;
private Double betrag;
private Double ust;
private String zweck;
}
My 2nd class:
public class Adresse {
private String name;
private Ort ort;
}
My 3rd class:
public class Ort {
private String plz;
private String name;
}
And maybe more generated sub-classes…
I want to get this json object:
{"adresse":{"name":null,"ort"{"plz":null,"name":null}},"betrag":null,"Ust":null,"zweck":null}
I am not allowed to change my POJO’s.
What kind of framework can do this for me? I tried gson but gson is not working with subclasses.
regards, dave
I got it working! With Java Reflection, json and it’s recursive!
Here the code:
userDefined() checks if a class is user defined or primitive, can be customized as you wish.
getSetterMethod() returns the setter Method of a field.
And finally, invokeSetters() invoke user defined object setter Methods and those of the subclasses! yea. So my Invoice object I would put here as a parameter:
and here it is: