Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON: JsonMappingException while try to deserialize object with null values
    primarykey
    data
    text
    <p>I try to deserialize object that contains null-properties and have the <code>JsonMappingException</code>.</p> <p><strong>What I do:</strong></p> <pre><code>String actual = "{\"@class\" : \"PersonResponse\"," + " \"id\" : \"PersonResponse\"," + " \"result\" : \"Ok\"," + " \"message\" : \"Send new person object to the client\"," + " \"person\" : {" + " \"id\" : 51," + " \"firstName\" : null}}"; ObjectMapper mapper = new ObjectMapper(); mapper.readValue(new StringReader(json), PersonResponse.class); //EXCEPTION! </code></pre> <p><strong>BUT</strong>: if to throw away <code>"firstName = null"</code> property - all works fine! I mean pass the next string:</p> <pre><code>String test = "{\"@class\" : \"PersonResponse\"," + " \"id\" : \"PersonResponse\"," + " \"result\" : \"Ok\"," + " \"message\" : \"Send new person object to the client\"," + " \"person\" : {" + " \"id\" : 51}}"; ObjectMapper mapper = new ObjectMapper(); mapper.readValue(new StringReader(json), PersonResponse.class); //ALL WORKS FINE! </code></pre> <p><strong>Question</strong>: How to avoid this exception or to pledge Jackson ignore null-values during serialization?</p> <p><strong>Throws:</strong></p> <p><strong><em>Message:</em></strong> </p> <pre><code>com.fasterxml.jackson.databind.MessageJsonException: com.fasterxml.jackson.databind.JsonMappingException: N/A (through reference chain: person.Create["person"]-&gt;Person["firstName"]) </code></pre> <p><strong><em>cause:</em></strong> </p> <pre><code>com.fasterxml.jackson.databind.MessageJsonException: com.fasterxml.jackson.databind.JsonMappingException: N/A (through reference chain: prson.Create["person"]-&gt;Person["firstName"]) </code></pre> <p><strong><em>cause:</em></strong> <code>java.lang.NullPointerException</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload