in util-jackson/src/main/scala/com/twitter/util/jackson/caseclass/package.scala [38:98]
private[twitter] def isAssignableFrom(fromType: Class[_], toType: Class[_]): Boolean =
Types.wrapperType(toType).isAssignableFrom(Types.wrapperType(fromType))
/** Create a new [[CaseClassBeanProperty]]. Returns the [[CaseClassBeanProperty]] and the JacksonInject.Value */
private[twitter] def newBeanProperty(
context: DeserializationContext,
javaType: JavaType,
optionalJavaType: Option[JavaType],
annotatedParameter: AnnotatedParameter,
annotations: Iterable[Annotation],
name: String,
index: Int
): CaseClassBeanProperty = {
// to support deserialization with JsonFormat and other Jackson annotations on fields,
// the Jackson annotations must be carried in the mutator of the ValueInjector.
val jacksonAnnotations = new AnnotationMap()
val contextAnnotationsMap = new AnnotationMap()
annotations.foreach { annotation =>
if (annotation.annotationType().isAnnotationPresent(classOf[JacksonAnnotation])) {
jacksonAnnotations.add(annotation)
} else {
contextAnnotationsMap.add(annotation)
}
}
val mutator: AnnotatedMember = optionalJavaType match {
case Some(optJavaType) =>
newAnnotatedParameter(
context,
annotatedParameter,
AnnotationMap.merge(jacksonAnnotations, contextAnnotationsMap),
optJavaType,
index)
case _ =>
newAnnotatedParameter(
context,
annotatedParameter,
AnnotationMap.merge(jacksonAnnotations, contextAnnotationsMap),
javaType,
index)
}
val jacksonInjectValue = context.getAnnotationIntrospector.findInjectableValue(mutator)
val beanProperty: BeanProperty = new ValueInjector(
/* propName = */ new PropertyName(name),
/* type = */ optionalJavaType.getOrElse(javaType),
/* mutator = */ mutator,
/* valueId = */ if (jacksonInjectValue == null) null else jacksonInjectValue.getId
) {
// ValueInjector no longer supports passing contextAnnotations as an
// argument as of jackson 2.9.x
// https://github.com/FasterXML/jackson-databind/commit/76381c528c9b75265e8b93bf6bb4532e4aa8e957#diff-dbcd29e987f27d95f964a674963a9066R24
private[this] val contextAnnotations = contextAnnotationsMap
override def getContextAnnotation[A <: Annotation](clazz: Class[A]): A = {
contextAnnotations.get[A](clazz)
}
}
CaseClassBeanProperty(valueObj = Option(jacksonInjectValue), property = beanProperty)
}