title: how to serialize multi-level json using jackson in spring?
body: <p>This is the response body that is expected out the endpoint /foo/bar.</p>
  
  <p>As you can see, this is nested <code>json</code> and hence for each level do I require a <code>Java object</code>. what is the efficient way to construct this?. I am using <code>Spring 4.1</code> which in turn uses <code>Jackson</code> to <code>serialize</code> POJOs.</p>
  
  <pre><code>{
      "user": {
          "status": {
              "state": "active",
              "message": [
                  "registered on 01.10.2015"
              ]
          }
      },
      "features": {
          "xbox": {
              "state": "enabled",
              "message": [
                  "foo",
                  "bar"
              ]
          },
        "playstation": {
              "state": "disabled",
              "message": [
                  "hello ",
                  "world"
              ]
          }
      }
  }
  </code></pre>
  
  <p>Here is something I have thought</p>
  
  <pre><code>  @RequestMapping("foo/bar")
      @ResponseBody
      public Result getData(long id){
  
      Result result = getUserData(id);
  
      return result;
      }
  
  public class Result {
  
     private User user;
  
     private List&lt;Feature&gt; features;
  
     //getters and setters
  
  }
  
  public class Status {
  
         private State state;
  
         private Message messages;
  
         //getters and setteers
  }
  
  public class State {
  
     private String state;
     //getters and setters
  }
  
  public class Message {
  
       private List&lt;String&gt; messages; 
       //getters and setters
  
  }
  </code></pre>
  
  <p>Similarly for "features" node, I will construct Java POJO for each level of Json object. I am aware of using <code>objectMapper</code> and <code>JsonNode</code> but wondering if it is possible to effectively construct nested json using java objects.</p>