Status: New
Owner: ----
Labels: Type-Defect Priority-Medium
New issue 513 by
haibison...@gmail.com: Deserialization with
Gson.fromJson() should *ignore* missing fields
http://code.google.com/p/google-gson/issues/detail?id=513
What steps will reproduce the problem?
1. Create a simple *non-static* class which initializes default values for
some fields:
public class Test {
int x = -1;
String s = "Hello";
}
2. Create new Gson and call `fromJson()` with missing fields:
Test t = new Gson().fromJson("{}", Test.class);
System.out.println(String.format("x=[%s] s=[%s]", t.x, t.s));
>> Results: x=[0] s=[null]
Test t = new Gson().fromJson("{\"x\": 1}", Test.class);
System.out.println(String.format("x=[%s] s=[%s]", t.x, t.s));
>> Results: x=[1] s=[null]
What is the expected output? What do you see instead?
As the test cases, I would like to expect default value for each field to
be the one that the class initializes. For instance with the first test
case, `x` should be `-1` and `s` should be "Hello".
What version of the product are you using? On what operating system?
- Gson 2.2.3
- OSes:
+ Fedora 18, 64 bit with OpenJDK 1.7.0_19;
+ Android API 4 and API 17;
Thanks,
Hai
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings