I can\'t find a simple way to add a custom field during serialization in Gson and I was hoping someone else may be able to help.
Here is a sample class to show my is
Use Gson.toJsonTree to get a JsonElement, with which you can interact dynamically.
Gson.toJsonTree
JsonElement
A a = getYourAInstanceHere(); Gson gson = new Gson(); JsonElement jsonElement = gson.toJsonTree(a); jsonElement.getAsJsonObject().addProperty("url_to_user", url); return gson.toJson(jsonElement);