@Override
  public Enum<?> deserialize(JsonParser jp, DeserializationContext ctxt)
      throws IOException, JsonProcessingException {
    JsonToken curr = jp.getCurrentToken();

    // Usually should just get string value:
    if (curr == JsonToken.VALUE_STRING || curr == JsonToken.FIELD_NAME) {
      String name = jp.getText();
      Enum<?> result = _resolver.findEnum(name);
      if (result == null
          && !ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
        throw ctxt.weirdStringException(
            name, _resolver.getEnumClass(), "value not one of declared Enum instance names");
      }
      return result;
    }
    // But let's consider int acceptable as well (if within ordinal range)
    if (curr == JsonToken.VALUE_NUMBER_INT) {
      /* ... unless told not to do that. :-)
       * (as per [JACKSON-412]
       */
      if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS)) {
        throw ctxt.mappingException(
            "Not allowed to deserialize Enum value out of JSON number (disable DeserializationConfig.DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS to allow)");
      }

      int index = jp.getIntValue();
      Enum<?> result = _resolver.getEnum(index);
      if (result == null
          && !ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
        throw ctxt.weirdNumberException(
            Integer.valueOf(index),
            _resolver.getEnumClass(),
            "index value outside legal index range [0.." + _resolver.lastValidIndex() + "]");
      }
      return result;
    }
    throw ctxt.mappingException(_resolver.getEnumClass());
  }