I have a list of objects, say:
List<Timestamp>
Each Timestamp object includes other objects, in particular, it has a Tag object.
class Timestamp { String time; ... Tag tag; ... }
Now each Tag object is identified by an identifier of type Integer.
class Tag { Integer id; ... }
For several reasons, I have to write a JSON representation of the entire list of timestamps in a file using the Gson library. In some cases, I need a decimal representation of the identifier of each tag, while in other cases I need identifiers in hexadecimal format.
How can I βswitchβ between two formats? Consider using the following command to write the entire list of Timestamp objects:
ps.println(gson.toJson(timestamps));
and I cannot add other fields / types / objects to the Tag class because the JSON representation will be different.
source share