Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Gson @SerializedName annotation on ALL fields, even when JSON name matches Java name #327

Closed
smaspe opened this issue Mar 25, 2015 · 5 comments
Milestone

Comments

@smaspe
Copy link

smaspe commented Mar 25, 2015

gson uses @SerializedName("json_name") when the name of the json field and the name of the java field are different. (already present to do the snake case to camel case)

It is also useful when the java code is obfuscated and the name of the java field is modified.

@joelittlejohn
Copy link
Owner

This should already be supported. Could you explain more about how you're
using jsonschema2pojo? Are you using annotationStyle=gson?
On 25 Mar 2015 22:44, "smaspe" notifications@github.com wrote:

gson uses @SerializedName("json_name") when the name of the json field
and the name of the java field are different. (already present to do the
snake case to camel case)

It is also useful when the java code is obfuscated and the name of the
java field is modified.


Reply to this email directly or view it on GitHub
#327.

@smaspe
Copy link
Author

smaspe commented Mar 26, 2015

I am using the online tool. By checking the Gson annotation style box, I do have SerializedName annotations for fields that don't have the same name in schema and java (such as field_name -> fieldName), but I would like to have that annotations for all fields, as the actual java field name will be obfuscated.

@joelittlejohn joelittlejohn changed the title Support systematique @SerializedName annotation for Gson Use Gson @SerializedName annotation on ALL fields, even when name JSON name matches Java name Mar 26, 2015
@joelittlejohn joelittlejohn added this to the 0.4.11 milestone Mar 26, 2015
@joelittlejohn
Copy link
Owner

Ah, I see what you mean. Feel free to submit a pull request for this.

@joelittlejohn joelittlejohn changed the title Use Gson @SerializedName annotation on ALL fields, even when name JSON name matches Java name Use Gson @SerializedName annotation on ALL fields, even when JSON name matches Java name Mar 26, 2015
@PNagesh
Copy link

PNagesh commented Jul 6, 2016

Hi ,

The @SerializedName doesnt seem to be working for an int value. I'm using java 8 and gson2.2.3. Any suggestions would be of great help.

@joelittlejohn
Copy link
Owner

@PNagesh I could be wrong, but I don't think you have diagnosed the problem correctly here. There's no reason that @SerializedName would fail to work for properties that have an int value when using Gson. Or do you mean using an int as the property key? This is not allowed in JSON.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants