private[this] def resolveWithDeserializerAnnotation()

in util-jackson/src/main/scala/com/twitter/util/jackson/caseclass/CaseClassField.scala [241:295]


  private[this] def resolveWithDeserializerAnnotation(
    context: DeserializationContext,
    fieldCodec: ObjectCodec,
    fieldJsonNode: JsonNode,
    forProperty: JacksonBeanProperty
  ): Option[Object] = jsonDeserializer match {
    case Some(annotation: JsonDeserialize)
        if isNotAssignableFrom(annotation.using, classOf[JsonDeserializer.None]) =>
      // specifies a deserializer to use. we don't want to run any processing of the field
      // node value here as the field is specified to be deserialized by some other deserializer
      Option(
        context
          .deserializerInstance(beanPropertyDefinition.getPrimaryMember, annotation.using)) match {
        case Some(deserializer) =>
          val treeTraversingParser = new TreeTraversingParser(fieldJsonNode, fieldCodec)
          try {
            // advance the parser to the next token for deserialization
            treeTraversingParser.nextToken
            if (isOption) {
              Some(
                Option(
                  deserializer
                    .deserialize(treeTraversingParser, context)))
            } else {
              Some(deserializer.deserialize(treeTraversingParser, context))
            }
          } finally {
            treeTraversingParser.close()
          }
        case _ =>
          Some(
            context.handleInstantiationProblem(
              javaType.getRawClass,
              annotation.using.toString,
              JsonMappingException.from(
                context,
                "Unable to locate/create deserializer specified by: " +
                  s"${annotation.getClass.getName}(using = ${annotation.using()})")
            )
          )
      }
    case Some(annotation: JsonDeserialize)
        if isNotAssignableFrom(annotation.contentAs, classOf[java.lang.Void]) =>
      // there is a @JsonDeserialize annotation but it merely states to deserialize as a specific type
      Some(
        parseFieldValue(
          context,
          fieldCodec,
          fieldJsonNode,
          forProperty,
          Some(annotation.contentAs)
        )
      )
    case _ => None
  }