I am Gson user (https://sites.google.com/site/gson/) and I have the following use case:
I have two pages that each retrieve JSon data as follows: One retrieves the primary key (ID) and field A and the second page retrieves the pk (ID) and field B开发者_开发技巧.
I switch from one page to another according to my user need (if they need field A or field B).
Insofar as I use the same value for the @SerializedName annotation in my JPA entity, both pages return the same data...
@javax.persistence.Column(name = "A")
@SerializedName("name")
private String A;
@javax.persistence.Column(name = "B")
@SerializedName("name")
private String B;
My question is as follows: is it possible to specify the names of the
JSon properties when invoking gsonInstance.toJson
instead of doing
this at the entity level? Also note that I need the same serialized
name for both fields (A and B).
Regards,
精彩评论