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

Map serialization, null values and @JsonValue #150

Closed
cowtowncoder opened this issue Jan 20, 2013 · 2 comments
Closed

Map serialization, null values and @JsonValue #150

cowtowncoder opened this issue Jan 20, 2013 · 2 comments

Comments

@cowtowncoder
Copy link
Member

(note: moved from FasterXML/jackson-core#50)


Jackson allows skip null values when serializing maps. This doesn't work, when map value is generated by the method annotated with @JsonValue. For example:

@JsonProperty
private Map<String, SomeClass> fields;

and:

class SomeClass {
  @JsonValue
  public String getValue() { ... }
}

result:

{"id1":"a","id2":null}
@cowtowncoder
Copy link
Member Author

This will be tricky one to resolve because code that handles inclusion rules will not see null but the POJO, and translation to null occurs later... when property name was already been written. This means that it is unlikely to be fixed for 2.1, as it will require bigger change.

@cowtowncoder
Copy link
Member Author

Come to think of this, I do not think this is supportable as defined.
Since actual values are not nulls, they will not be blocked by NON_NULL. Jackson 2.9 will support custom inclusion rules (see @JsonInclude and specifically content and new contentFilter).
Without this, an alternative would be custom serializer for SomeClass, which may define isEmpty() method; and if properly defined could then used NON_EMPTY to remove such entries.

But the trick is that determination MUST be based on Java value -- instance of SomeClass -- and not on whatever @JsonValue accessor may convert it to.

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

No branches or pull requests

1 participant