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

Make it possible to ignore nulls #43

Closed
francisdb opened this issue Sep 24, 2014 · 2 comments
Closed

Make it possible to ignore nulls #43

francisdb opened this issue Sep 24, 2014 · 2 comments

Comments

@francisdb
Copy link

I would like to allow this:

{
  name: "test"
  age: null
}

to be equal to

{
  name: "test"
}
@jmayday
Copy link

jmayday commented May 19, 2015

When working with some specific class it's possible to annotate it with @JsonInclude(Include.NON_EMPTY) or also prepare own ObjectMapper implementation with Serializers which redefine isEmpty() method to apply even more sophisticated logic. Details described here FasterXML/jackson-databind#730

But it's tricky for me as well to ignore nulls when dealing with raw jsons (then Include strategy nor custom ObjectMapper doesn't do the job).

@carterpage
Copy link
Member

If the second one is the expected value, and you use LENIENT or STRICT_ORDER modes, then this will pass. However, if the first one (with age:null) is the expected value, it will fail because technically speaking, the field actually exists in the JSON tree. Therefore, this is WAI. You can try jmayday's advice, or write a scrubber utility to remove null fields before passing it to JSONAssert.

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

3 participants