Skip to content

Custom deserializer not called for explicit null value #171

@GoogleCodeExporter

Description

@GoogleCodeExporter
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 hell...@gmail.com on 3 Nov 2009 at 11:33

Attachments:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions