Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom deserializer not called for explicit null value #171

Closed
GoogleCodeExporter opened this issue Mar 19, 2015 · 4 comments
Closed

Custom deserializer not called for explicit null value #171

GoogleCodeExporter opened this issue Mar 19, 2015 · 4 comments

Comments

@GoogleCodeExporter
Copy link

When a json object contains an explicit null for a field, the custom
deserializer for that field type is never called, rather the field is
simply set to null. This makes it impossible to map json nulls to some
non-null value in a consistent way. It also makes it impossible to have
guaranteed non-null fields in objects which are deserialized from json.

The handling of explicit nulls and missing values is also inconsistent: in
the case of an explicit null, the Java object's field is set to null. In
the case of a missing value, the field is left alone (as initialized by the
no-arg constructor).

The behavior for missing values is reasonable, but the behavior for
explicit nulls is very difficult to work around. Explicit null values
should (perhaps optionally) be passed through the custom deserializer.

What steps will reproduce the problem?
1. compile the attached file
2. run it

What is the expected output? What do you see instead?
Expected output:
  NullInner should equal NullInner
  NullInner should equal NullInner
OR:
  NullInner should equal NullInner
  InitInner should equal NullInner
I see:
  null should equal NullInner
  InitInner should equal NullInner

What version of the product are you using? On what operating system?
gson 1.4


Original issue reported on code.google.com by [email protected] on 3 Nov 2009 at 11:33

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant