title: Jackson throws NPE during deserialization on missing property
body: <p>I'm still getting NPE while trying to deserialize an JSON. I wish to put a default value (0 / null) if property is missing. This is my Spring Boot configuration bean:</p>
  
  <pre><code>@Bean
  public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
      MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
      jsonConverter.setObjectMapper(objectMapper());
      return jsonConverter;
  }
  
  ObjectMapper objectMapper() {
      SimpleModule simpleModule = new SimpleModule();
      simpleModule.addDeserializer(ProductBasicDto.class, new ProductDeserializer());
  
      ObjectMapper mapper = new ObjectMapper()
              .configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false)
              .configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, false)
              .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
              .configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, false)
              .configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false);
  
      mapper.registerModule(simpleModule);
      return mapper;
  }
  </code></pre>
  
  <p>My custom deserializer:</p>
  
  <pre><code>@Override
  public ProductBasicDtoWrapper deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
      JsonNode node = jsonParser.getCodec().readTree(jsonParser);
      System.out.println(node.get("id").asLong()); // here it throws NPE
   return null; // ignore that, just for testing
  }
  </code></pre>
  
  <p>json:</p>
  
  <pre><code>{
    "name": "js",
    "category": "CoNiFer"
  }
  </code></pre>
  
  <p>and execption:</p>
  
  <pre><code>java.lang.NullPointerException: null
  at api.product.infrastructure.ProductDeserializer.deserialize(ProductDeserializer.java:19)
  at api.product.infrastructure.ProductDeserializer.deserialize(ProductDeserializer.java:14)
  at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4001)
  at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3072)
  at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:235)
  at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:223)
  at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:206)
  at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:157)
  at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:130)
  at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:124)
  at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:161)
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:131)
  at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776)
  at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
  </code></pre>
  
  <ol>
  <li>How can I avoid this NPE? </li>
  <li>Is it possible to put 0 / null values without explict checks in deserializer if property(like id in this example) is missing?</li>
  </ol>
  
  <p>EDIT: Added some code examples</p>
  
  <p>Let's say this is my DTO class:</p>
  
  <pre><code>class MyDto implements Serializable {
  private final String firstName;
  private final String lastName;
  }
  </code></pre>
  
  <p>Now I'm creating my custom mapper:</p>
  
  <pre><code>@Override
  public ProductBasicDtoWrapper deserialize(JsonParser jsonParser, 
  DeserializationContext deserializationContext) throws IOException, 
  JsonProcessingException {
   objectMapper.convertValue(jsonNode, MyDto.class);
  </code></pre>
  
  <p>...</p>
  
  <p>Now I decided to add additional Integer to MyDto:</p>
  
  <pre><code>    class MyDto implements Serializable {
  private final String firstName;
  private final String lastName;
  private final Integer age;
  }
  </code></pre>
  
  <p>It's great it doesn't needs changing ANYTHING else (in my mapper class). But assume I got this kind of json</p>
  
  <pre><code> {
     "firstName": "name"
  }
  </code></pre>
  
  <p>Now it throws NPE. So the idea is to check if values are null in mapper. Let's do it:</p>
  
  <pre><code>@Override
  public ProductBasicDtoWrapper deserialize(JsonParser jsonParser, 
  DeserializationContext deserializationContext) throws IOException, 
  JsonProcessingException {
  JsonNode node = jsonParser.getCodec().readTree(jsonParser);
    node.get("firstName") == null ?
    node.get("lastName") == null ?
    node.get("age") == null ?
  </code></pre>
  
  <p>}</p>
  
  <p>Okay it works, now let's say I added one more attribute to my DTO class</p>
  
  <pre><code>class MyDto implements Serializable {
  private final String firstName;
  private final String lastName;
  private final Integer age;
  private final String card;
  </code></pre>
  
  <p>}</p>
  
  <p>The problem is, in this case I have to change ALSO my mapper class because 4th parameter isn't handled.</p>