title: Jackson serialization: how to ignore superclass properties
body: <p>I want to serialize a POJO class which is not under my control, but want to avoid serializing any of the properties which are coming from the superclass, and not from the final class. Example:</p>
  
  <pre><code>public class MyGeneratedRecord extends org.jooq.impl.UpdatableRecordImpl&lt;...&gt;,
      example.generated.tables.interfaces.IMyGenerated {
    public void setField1(...);
    public Integer getField1();
  
    public void setField2(...);
    public Integer getField2();
  ...
  }
  </code></pre>
  
  <p>You can guess from the example that that this class is generated by JOOQ, and inherits from a complex base class UpdatableRecordImpl which also has some bean property-like methods, which cause problems during the serialization. Also, I have several similar classes, so it would be good to avoid duplicating the same solution for all of my generated POJOs.</p>
  
  <p>I have found the following possible solutions so far:</p>
  
  <ul>
  <li><p>ignore the specific fields coming from superclass using mixin technique like this: <a href="https://stackoverflow.com/questions/7421474/how-can-i-tell-jackson-to-ignore-a-property-for-which-i-dont-have-control-over">How can I tell jackson to ignore a property for which I don&#39;t have control over the source code?</a></p>
  
  <p>The problem with this is that if the base class changes (e.g., a new getAnything() method appears in it), it can break my implementation.</p></li>
  <li><p>implement a custom serializer and handle the issue there. This seems a bit overkill to me.</p></li>
  <li><p>as incidentally I have an interface which describes exactly the properties I want to serialize, maybe I can mixin a @JsonSerialize(as=IMyGenerated.class) annotation...? Can I use this for my purpose?</p></li>
  </ul>
  
  <p>But, from pure design point of view, the best would be to be able to tell jackson that I want to serialize only the final class' properties, and ignore all the inherited ones. Is there a way to do that?</p>
  
  <p>Thanks in advance.</p>