title: Spring boot JsonMappingException: Object is null
body: <p>I have a @RestController that returns net.sf.json.JSONObject:</p>
  
  <pre><code>@PostMapping("/list")
  public JSONObject listStuff(HttpServletRequest inRequest, HttpServletResponse inResponse) {
      JSONObject json = new JSONObject();
      ...
      return json;
  }
  </code></pre>
  
  <p>When JSONObject contains null reference, the following exception is thrown:</p>
  
  <pre><code>Could not write JSON: Object is null; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Object is null (through reference chain: net.sf.json.JSONObject[\"list\"]-&gt;net.sf.json.JSONArray[0]-&gt;net.sf.json.JSONObject[\"object\"]-&gt;net.sf.json.JSONNull[\"empty\"])"
  
  </code></pre>
  
  <p>This is the legacy code that we are now cleaning up and at some point we will get rid of explicit JSON manipulations, but this will be a huge change, for now I would like to just get rid of the exception.
  I tried with following solutions:</p>
  
  <ol>
  <li>Define <code>Include.NON_NULL</code> in Spring's Object Mapper - so this piece of code in my <code>WebMvcConfigurationSupportClass</code>:</li>
  </ol>
  
  <pre><code>@Override
  public void configureMessageConverters(List&lt;HttpMessageConverter&lt;?&gt;&gt; converters) 
  {
      ObjectMapper webObjectMapper = objectMapper.copy();
      webObjectMapper.setSerializationInclusion(Include.NON_NULL);
      converters.add(new MappingJackson2HttpMessageConverter(webObjectMapper)); 
  }
  </code></pre>
  
  <ol start="2">
  <li>Setting following property in application.yml:
  <code>spring.jackson.default-property-inclusion=non_null</code></li>
  <li>Checking the version of <code>com.fasterxml.jackson</code> - the only found in the dependency tree is 2.9.7.</li>
  </ol>
  
  <p>None of the above helped.</p>
  
  <p>Any suggestions on how to tell Spring to ignore null values in net.sf.json.JSONObjects?</p>