title: JSON Formatting with Jersey and Jackson
body: <p>Using Java 6, Tomcat 7, Jersey 1.15, Jackson 1.9.9, created a simple web service which has the following architecture:</p>
  
  <p>My POJOs (model classes):</p>
  
  <p>Family.java:</p>
  
  <pre><code>import javax.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement
  public class Family {
  
      private String father;
      private String mother;
  
      private List&lt;Children&gt; children;
  
      // Getter &amp; Setters
  }
  </code></pre>
  
  <p>Children.java:</p>
  
  <pre><code>import javax.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement
  public class Children {
  
      private String name;
      private String age;
      private String gender;
  
      // Getters &amp; Setters
  }
  </code></pre>
  
  <p>Using a Utility Class, I decided to hard code the POJOs as follows:</p>
  
  <pre><code>public class FamilyUtil {
      public static Family getFamily() {
          Family family = new Family();
          family.setFather("Joe");
          family.setMother("Jennifer");
  
          Children child = new Children();
          child.setName("Jimmy");
          child.setAge("12");
          child.setGender("male");
          List&lt;Children&gt; children = new ArrayList&lt;Children&gt;();
  
          children.add(child);
  
          family.setChildren(children);
          return family;
      }
  }
  </code></pre>
  
  <p>MyWebService:</p>
  
  <pre><code>@Path("")
  public class MyWebService {
  
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public Family getFamily {
          return FamilyUtil.getFamily();
      }
  }
  </code></pre>
  
  <p>Produces:</p>
  
  <pre><code>{"children": [{"age":"12","gender":"male","name":"Jimmy"}],"father":"Joe", "mother":"Jennifer"}
  </code></pre>
  
  <p>What I need to do is have it produce it in a more legible manner:</p>
  
  <pre><code>{ 
      "father":"Joe", 
      "mother":"Jennifer",
      "children": 
      [
          {
              "name":"Jimmy",
              "age":"12","
              "gender":"male"
          }
      ]
  }
  </code></pre>
  
  <p>Just am seeking a way to implement so it can display some type of formatting with indentation / tabs.</p>
  
  <p>Would be very grateful if someone could assist me.</p>
  
  <p>Thank you for taking the time to read this. </p>