I’m using Gson 2.2‘s toJson() method to serialize a java object into a json string. The java object is of type:
public class LOB implements Serializable{
private int id;
private LOBType type;
private TypeSpecificData data;
public class TypeSpecificData {
private String a;
private int b;
}
}
All fields of the object are serialized except for data field of type TypeSpecificData.
How do I include this field as well in the json string ?
Currently I’m serializing like shown below:
String jsonString = new Gson().toJson(lob_instance);
By default Gson will not serialize null objects refereces. Please check it.
Link to GSON documentation