title: How to directly write to a JSON object (ObjectNode) from ObjectMapper in Jackson JSON?
body: <p>I'm trying to output to a JSON object in Jackson JSON. However, I couldn't get the JSON object using the following code.</p>
  
  <pre><code>public class MyClass {
  
          private ObjectNode jsonObj;
  
          public ObjectNode getJson() {
                ObjectMapper mapper = new ObjectMapper();
                // some code to generate the Object user...
                mapper.writeValue(new File("result.json"), user);
                jsonObj = mapper.createObjectNode();
                return jsonObj;
          }
  
  }
  </code></pre>
  
  <p>After the program runs, the file <code>result.json</code> contains the correct JSON data. However, <code>jsonObj</code> is empty (<code>jsonObj={}</code>). I looked up the Javadoc of <a href="http://jackson.codehaus.org/1.7.9/javadoc/org/codehaus/jackson/map/ObjectMapper.html">ObjectMapper</a> but couldn't find an easy way to write to a <code>ObjectNode</code> (JSON object in Jackson). There is no method in <code>ObjectMapper</code> like the following:</p>
  
  <pre><code>public void writeValue(ObjectNode json, Object value)
  </code></pre>
  
  <p>How to write to an <code>ObjectNode</code> directly from <code>ObjectMapper</code>?</p>