I am uploading an object to a server and the "value" field accepts Strings, Ints, and Boolean values.
Here is the model with the clearly failed application of @SeralizedName.
public class InspectionFormItems {
@SerializedName("id")
private Integer id;
@SerializedName("type")
private String type;
@SerializedName("value")
private String stringValue;
@SerializedName("value")
private boolean boolValue;
@SerializedName("value")
private int intValue;
@SerializedName("name")
private String name;
@SerializedName("children")
ArrayList<ArrayList<InspectionFormItems>> subitems;
}
Most of the stackoverflow results I found were for Serializing entire objects, or De-Serializing. Some of my ideas were..
- Is it possible to remove @SerializedName from the three value fields and only serialize the value that isn't null?
- Can I build some sort of optional data-type-object in java that is set based on the data type that has a value?
This object is part of a larger object and the subitems object has a fair bit of depth to it it just as a note. I expect this to be a duplicate of some question, I just have been unable to find it so far.
Edit:
This is the closest question I have found though I would rather not custom serialize the entire object the way this person has as there could be 40-100 of these objects in this outgoing json gson-same-field-name-different-types-serialize
I've also discovered I can not dynamically set the @SerializedValue attribute is-it-possible-to-pass-method-parameter-to-annotation-on-a-method?
3rd Edit: Let me know if I should delete a bunch of this excess. I am trying to implement this method - inner serialization - this answer though is old an tough to make work right now.