DonaldDu / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Gson 2.0 backwards incompatibility: an absent Json field is set to new Object() instead of null. #389

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
https://groups.google.com/forum/?hl=en_US#!topic/google-gson/L2ALXLxguNY

 was using gson-1.2.2 version and decided to upgrade to the gson-2.0.
The only drawback I've had so far is that in version 1.2.2, when a
field is ignored in the json, it is converted to null.
For example this class.

Class Persona{
private String nombre;
private Long id;
private Genero genero = new Genero();
}

If I send the following json

{"id":1,"nombre":"juan"}

In version 1.2.2 the java object

nombre = “juan”
id= 1
genero = null

Performing tests on version 2.0.  I have

nombre = “juan”
id= 1
genero = object

What can i do? .. or that is the default in new versions?

Original issue reported on code.google.com by inder123 on 16 Dec 2011 at 4:54

GoogleCodeExporter commented 9 years ago
This is not a valid issue.
Added a test for this in r1082

I tested this test with r1016 (Gson 2.0) as well and it passed.

Original comment by inder123 on 16 Dec 2011 at 5:23