title: How to convert a Java object to a Jackson ObjectNode?
body: <p>I have a Java object class, say, <code>Student</code>. How to convert it to an <code>ObjectNode</code>? It can be a nested object (multi-level nesting).</p>
  
  <p>I am trying following code to convert the object to <code>ObjectNode</code>, but it is first converting the object to a <code>String</code> and then converting it to <code>ObjectNode</code> which looks costly operation.</p>
  
  <pre class="lang-java prettyprint-override"><code>ObjectMapper mapper = new ObjectMapper();
  mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
  
  try {
      String json = mapper.writeValueAsString(student);
      JsonNode jsonNode = mapper.readTree(json);
      ObjectNode objectNode = jsonNode.deepCopy();
      return objectNode;
  } catch (Exception e) {
      // Handle exception
  }
  </code></pre>
  
  <p>I am looking for a better approach because I feel by this approach, I am doing 2 levels serialization/deserialization. </p>
  
  <pre class="lang-java prettyprint-override"><code>public class Student {
      public String name;
      public int id;
      public ArrayList&lt;Subjects&gt; subjects;
      public Address address;
  }
  </code></pre>