I am using gson.fromJson(json,class)
to convert json into a Java Object.
If I do not pass a parameter (other than an int
) in the json, it is deserialized as null
, but the int
variable in the object is deserialized as 0.
So my question is, is there any annotation or any way I can use, so that if I do not pass the int
parameter in the json, it is not deserialized as 0. Ideally, it would not show up at all in the object, but at the very least it would be null
.
For example, the following json: {"name":"asas"}
If I have the above json, then using gson.fromJson()
, will automatically deserialized id
as 0.
Is there a way to eliminate that?
public class Student{
String name;
int id;
//getters and setters
}