开发者

Issue with @SerializedName annotation and the JSon Gson library

开发者 https://www.devze.com 2023-04-12 09:58 出处:网络
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

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,

0

精彩评论

暂无评论...
验证码 换一张
取 消