title: Jackson serialize only interface methods
body: <p>I have one object <em>A</em> with some methods <em>ma</em>, <em>mb</em>, <em>mc</em> and this object implements an interface <em>B</em> with only <em>ma</em> and <em>mb</em>.</p>
  
  <p>When I serialize <em>B</em> I expect only <em>ma</em> and <em>mb</em> as a json response but I get as well <em>mc</em>.</p>
  
  <p>I'd like to automatize this behaviour so that all the classes I serialize get serialized based on the interface and not on the implementation.</p>
  
  <p>How should I do that?</p>
  
  <p>Example:</p>
  
  <pre><code>public interface Interf {
      public boolean isNo();
  
      public int getCountI();
  
      public long getLonGuis();
  }
  </code></pre>
  
  <p>Implementation:</p>
  
  <pre><code>public class Impl implements Interf {
  
      private final String patata = "Patata";
  
      private final Integer count = 231321;
  
      private final Boolean yes = true;
  
      private final boolean no = false;
  
      private final int countI = 23;
  
      private final long lonGuis = 4324523423423423432L;
  
      public String getPatata() {
          return patata;
      }
  
  
      public Integer getCount() {
          return count;
      }
  
  
      public Boolean getYes() {
          return yes;
      }
  
  
      public boolean isNo() {
          return no;
      }
  
  
      public int getCountI() {
          return countI;
      }
  
      public long getLonGuis() {
          return lonGuis;
      }
  
  }
  </code></pre>
  
  <p>Serialization:</p>
  
  <pre><code>    ObjectMapper mapper = new ObjectMapper();
  
      Interf interf = new Impl();
      String str = mapper.writeValueAsString(interf);
  
      System.out.println(str);
  </code></pre>
  
  <p>Response:</p>
  
  <pre><code> {
      "patata": "Patata",
      "count": 231321,
      "yes": true,
      "no": false,
      "countI": 23,
      "lonGuis": 4324523423423423500
  } 
  </code></pre>
  
  <p>Expected response:</p>
  
  <pre><code> {
      "no": false,
      "countI": 23,
      "lonGuis": 4324523423423423500
   } 
  </code></pre>