I have previously JSON response in REST API like below,
Example,
{"id":"1234"}.
I created an POJO class to set it like below.
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Example {
@SerializedName("id")
@Expose
private String id;
/**
*
* @return
* The id
*/
public String getId() {
return id;
}
/**
*
* @param id
* The id
*/
public void setId(String id) {
this.id = id;
}
}
And I am parsing with GSON like below
Example response = new Gson().fromJson(jsonResponse, Example .class);
Now, response is changed to
{"Id":"1234"}
And my whole parsing is returning me null due to initial capital letter.
I tried many things to solve it out but I can't get any solution for it. I have only suggestions like
- you should change name of @SerializedName with initial capital (but I have thousands of objects)
Is there any solution that GSON won't depend upon capitalization or lower case of key?