title: How to access default jackson serialization in a custom serializer with the same object
body: <p>Copy here an old answer, that only worked to some people.
  The question is,</p>
  
  <ol>
  <li><p>Where should I locate the register part of the BeanSerializerModifier ?</p></li>
  <li><p>what do I do with the ObjectMapper object ?</p></li>
  </ol>
  
  <p>A BeanSerializerModifier will provide you access to the default serialization.</p>
  
  <p>Inject a default serializer into the custom serializer</p>
  
  <pre><code>public class MyClassSerializer extends JsonSerializer&lt;MyClass&gt; {
      private final JsonSerializer&lt;Object&gt; defaultSerializer;
  
      public MyClassSerializer(JsonSerializer&lt;Object&gt; defaultSerializer) {
          this.defaultSerializer = checkNotNull(defaultSerializer);
      }
  
      @Override
      public void serialize(MyClass myclass, JsonGenerator gen, SerializerProvider provider) throws IOException {
          if (myclass.getSomeProperty() == true) {
              provider.setAttribute("special", true);
          }
          defaultSerializer.serialize(myclass, gen, provider);
      }
  }
  </code></pre>
  
  <p>Create a BeanSerializerModifier for MyClass</p>
  
  <pre><code>public class MyClassSerializerModifier extends BeanSerializerModifier {
      @Override
      public JsonSerializer&lt;?&gt; modifySerializer(SerializationConfig config, BeanDescription beanDesc, JsonSerializer&lt;?&gt; serializer) {
          if (beanDesc.getBeanClass() == MySpecificClass.class) {
              return new MyClassSerializer((JsonSerializer&lt;Object&gt;) serializer);
          }
          return serializer;
      }
  }
  </code></pre>
  
  <p>Register the serializer modifier</p>
  
  <pre><code>ObjectMapper om = new ObjectMapper()
          .registerModule(new SimpleModule()
                  .setSerializerModifier(new MyClassSerializerModifier()));
  </code></pre>