title: Duplicate JSON Field with Jackson
body: <p>I am using Jackson for JSON (de)serialization in conjunction with Spring. However I am having an issue with a field being twice in some cases.</p>
  
  <p>I have an abstract class: </p>
  
  <pre><code>@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "mimeType")
  @JsonSubTypes({
      @JsonSubTypes.Type(value = ImageBookmarkJsonModel.class, name = "image/jpeg"),
      @JsonSubTypes.Type(value = EpubBookmarkJsonModel.class, name = "application/epub+zip")
  })
  public abstract class AbstractBookmarkJsonModel extends AbstractJsonModel {
      protected String mimeType;
      // Removed other fields for brevity
  
      public String getMimeType() {
          return mimeType;
      }
  
      public void setMimeType(String mimeType) {
          this.mimeType = mimeType;
      }
  
      @Override
      public String toString() {
          ObjectMapper mapper = new ObjectMapper();
  
          try {
              return mapper.writeValueAsString(this);
          } catch (IOException e) {
              throw new IllegalStateException("Cannot convert object of type " + this.getClass().toString() + " to JSON", e);
          }
      }
  }
  </code></pre>
  
  <p>And a concrete class extend the abstract:</p>
  
  <pre><code>public class EpubBookmarkJsonModel extends AbstractBookmarkJsonModel {
      private static final long serialVersionUID = 1L;
      // Removed other fields for brevity
  
      public EpubBookmarkJsonModel() {
          this.mimeType = "application/epub+zip";
      }
  }
  </code></pre>
  
  <p>The problem is that when I serialize this JSON, I get a duplicate <code>mimeType</code> field:</p>
  
  <pre><code>{
    "mimeType": "application/epub+zip",
    "mimeType": "application/epub+zip",
    "userId": 24,
    "acid": "ACID-000000000029087",
    "added": "2013-08-14T12:02:17Z",
    "epubBookmarkId": 34,
    "cfi": "epubcfi(/6/4!/2/68)",
    "context": "CONTEXT"
  }
  </code></pre>
  
  <p>I have tried using the recommendation of <a href="https://stackoverflow.com/questions/13262662/duplicate-json-property-when-converting-java-object-to-json-string-using-jackson">previous</a> <a href="https://stackoverflow.com/questions/7105745/how-to-specify-jackson-to-only-use-fields-preferably-globally">answers</a> to use the <code>@JsonAutoDetect</code> annotation to specify that only fields on a class should be used as well as setting the same on the <code>ObjectMapper</code>, however this does not fix the problem.</p>
  
  <p>Annotation:</p>
  
  <pre><code>@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE,
          setterVisibility = JsonAutoDetect.Visibility.NONE, creatorVisibility = JsonAutoDetect.Visibility.NONE,
          isGetterVisibility = JsonAutoDetect.Visibility.NONE)
  </code></pre>
  
  <p>ObjectMapper:</p>
  
  <pre><code>    ObjectMapper mapper = new ObjectMapper();
      mapper.getSerializationConfig().getDefaultVisibilityChecker()
              .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
              .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
              .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
              .withCreatorVisibility(JsonAutoDetect.Visibility.NONE);
  </code></pre>