title: Custom JsonDeserializer using inheritance causes StackOverflowError
body: <p>I'm having an issue with a custom JsonDeserializer. I'm trying to use different implementations of an abstract class depending on the JSON message received by a Rest service call (if the data is an <code>Array</code> use one and if it's a <code>String</code> use another):</p>
  
  <pre><code>@Path("/rest/cipher")
  public interface CipherManager {
  
      @POST
      @Consumes("application/json")
      @Produces("application/json")
      @Path("/encrypt")
      public Response cipher(AbstractCipherRequestBean jsonRequestData);
  }
  </code></pre>
  
  <p>The deserializer looks like this:</p>
  
  <pre><code>public class CipherRequestDeserializer extends JsonDeserializer&lt;AbstractCipherRequestBean&gt; {
  
  @Override
  public AbstractCipherRequestBean deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
      ObjectMapper mapper = (ObjectMapper) jp.getCodec();
      ObjectNode root = (ObjectNode) mapper.readTree(jp);
      Class&lt;? extends AbstractCipherRequestBean&gt; abstractCipherRequestBeanClass = null;
      Iterator&lt;Entry&lt;String, JsonNode&gt;&gt; elementsIterator = root.getFields();
      while (elementsIterator.hasNext()) {
          Entry&lt;String, JsonNode&gt; element = elementsIterator.next();
          String name = element.getKey();
          if(name.equals("b64Data")){
              if(element.getValue().isArray()){
                  abstractCipherRequestBeanClass = CipherMultRequestBean.class;
              }else{
                  abstractCipherRequestBeanClass = CipherRequestBean.class;
              }
          }
      }
      if (abstractCipherRequestBeanClass == null){
          return null;
      }
      return mapper.readValue(root, abstractCipherRequestBeanClass);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The inheritance is the following:</p>
  
  <pre><code>public class RequestBean {
      protected String b64Data;
      ...
  }
  
  @JsonDeserialize(using = CipherRequestDeserializer.class)
  public abstract class AbstractCipherRequestBean extends RequestBean{
      ...
  }
  
  public class CipherRequestBean extends AbstractCipherRequestBean{
      ...
  }
  
  public class CipherMultRequestBean extends AbstractCipherRequestBean {
      private List&lt;String&gt; b64Data;
      ...
  }
  </code></pre>
  
  <p>I believe that since both implementations are inheriting the <code>@JsonDeserialize</code> annotation, each call to <code>mapper.readValue(root, abstractCipherRequestBeanClass)</code> calles the <code>deserialize</code> method again, ending in a StackOverflowError.</p>
  
  <p>Is there a way to avoid this? Since at the end I'm calling the <code>mapper</code> with an actual class, I thought it'd use the default <code>mapper</code> implementation, not the <code>CipherRequestDeserializer</code> one.</p>