title: Java - POJO Serialization Jackson 2.0
body: <p>I've been scanning stack overflow all day and have not come across a viable solution for my problem. </p>
  
  <p>I have a pojo that has primitive types and nested objects. For example...</p>
  
  <pre><code>@JsonIgnoreProperties({"duration", "errorCode", "haveFieldsChanged", 
  "serviceRequestToken", "storedProcDuration"}) // Abstract Base Class 
   properties
  class Bus extends AbstractBaseClass implements Serializable{
  
      @JsonIgnore
      private static final long serialVersionId = 1;
  
      @JsonProperty("name")
      String name;
  
      @JsonProperty("id")
      int id;
  
      @JsonProperty("students")
      List&lt;Student&gt; students; // Nested Objects
  
      @JsonProperty("employer")
      Employer employer; //Nested object
  
      // Getters and setters - none are annotated
  
  @JsonRootName(value = "student")
  class Student implements Serializable{
      // student fields
  }
  
  @JsonRootName(value = "statusType")
  class Employer implements Serializable{
  
      @JsonProperty("id")
      int id;
  }
  </code></pre>
  
  <p>When I serialize my Bus object, jackson has no problem creating the proper structure for name, id, and my list of students. However, it will skip over Employer entirely leaving it absent from the json. See below. </p>
  
  <pre><code>{
    "name":"Sean",
    "id": 1,
    "students":[student objects...]
  }
  </code></pre>
  
  <p>I have tried @JsonProperty, @JsonSerialize(as = Employer.class), I tried building map for the employer object. I feel like I have exhausted most options. Is there something I am missing?</p>
  
  <p>I ran into stack overflow exceptions trying some other annotations. I appreciate any help I can get.</p>
  
  <p>The reason I added @JsonProperty to the fields is to help drive deserialization. I think this may be the root cause for serialization, but I am not certain.</p>
  
  <p>Serialization Implementation</p>
  
  <pre><code>private String serializeBus(Bus bus) throws Exception {
      ObjectMapper mapper = new ObjectMapper();
      mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
      mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
      String json = null;
      try {
          json = mapper.writeValueAsString(bus);
      } catch (JsonProcessingException e) {
          logger.error("Error serializing bus");
          throw new Exception(e);
      }
      return json;
  }
  </code></pre>
  
  <p>Thank you! </p>