title: Hiding protected fields from Jackson serialization
body: <p>For some reason I am not able to hide protected fields (without setter), via <code>ObjectMapper</code> configuration, from being serialized to a JSON string.</p>
  
  <p>My POJO:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class Item {
  
      protected String sn;
      private String name;
  
      public Item(){
          sn = "43254667";
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getSn() {
          return sn;
      }
  
  }
  </code></pre>
  
  <p>My mapper:</p>
  
  <pre class="lang-json prettyprint-override"><code>mapper.setVisibility(PropertyAccessor.SETTER, Visibility.PUBLIC_ONLY);
  mapper.setVisibility(PropertyAccessor.GETTER, Visibility.PUBLIC_ONLY);
  mapper.setVisibility(PropertyAccessor.FIELD, Visibility.NONE);
  </code></pre>
  
  <p>The output is:</p>
  
  <pre class="lang-json prettyprint-override"><code>{
    "sn" : "43254667",
    "name" : "abc"
  }
  </code></pre>
  
  <p><strong>UPDATE:</strong> I cannot modify the <code>Item</code> class, hence I cannot use annotations.</p>