I am searching for this for quite some time now but still, it is not clear to me. I have a JSON file which looks like this:
{
"Name" : "Foo Bar",
"Grade" : "Some Grade",
"Org" : "Some Org"
}
For deserializing this JSON (using gson) I have created a Java class called StudentDetails.java
which looks like this:
public class StudentDetails
{
public String name;
public String grade;
public String org;
}
Now I have a couple of questions regarding this:
- Will gson automatically maps the fields in
StudentDetails.java
with corresponding keys even if the fields start with lower case and keys start from upper case in the JSON file. I have looked for@SerializedName
but my code works without even using it. On the contrary if I am using something like@SerializedName("Name)
with name field, it's getting assigned to null after deserialization. I am so confused right now. - Will deserialization work without even getter and setter methods? In jackson you write setter and getter methods.
- If above is true, does it work even in the case of private fields?