Search in sources :

Example 1 with AnnotationMap

use of com.fasterxml.jackson.databind.introspect.AnnotationMap in project chassis by Kixeye.

the class ConstructorParameterModelProperty method getModelProperties.

/**
     * Creates a collection of ConstructorParameterModelProperty objects from the arguments of the given ResolvedConstructor.
     * Only args annotated with @JsonProperty are included. Scala Case Classes are a special case and do not require the annotation.
     *
     * @param resolvedConstructor the constructor to get
     * @param alternateTypeProvider for resolving alternative types for the found arguments
     * @return the collection of ConstructorParameterModelProperty objects
     */
public static ImmutableList<ConstructorParameterModelProperty> getModelProperties(ResolvedConstructor resolvedConstructor, AlternateTypeProvider alternateTypeProvider) {
    Builder<ConstructorParameterModelProperty> listBuilder = new Builder<>();
    if (resolvedConstructor.getRawMember().getAnnotation(JsonCreator.class) != null || scala.Product.class.isAssignableFrom(resolvedConstructor.getDeclaringType().getErasedType())) {
        //constructor for normal classes must be annotated with @JsonCreator. Scala Case Classes are a special case
        for (int i = 0; i < resolvedConstructor.getArgumentCount(); i++) {
            AnnotationMap annotationMap = annotationMap(resolvedConstructor.getRawMember().getParameterAnnotations()[i]);
            ResolvedType parameterType = resolvedConstructor.getArgumentType(i);
            if (annotationMap.get(JsonProperty.class) != null) {
                listBuilder.add(new ConstructorParameterModelProperty(parameterType, alternateTypeProvider, annotationMap));
            }
        }
    }
    return listBuilder.build();
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) AnnotationMap(com.fasterxml.jackson.databind.introspect.AnnotationMap) Builder(com.google.common.collect.ImmutableList.Builder) ResolvedType(com.fasterxml.classmate.ResolvedType)

Aggregations

ResolvedType (com.fasterxml.classmate.ResolvedType)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 AnnotationMap (com.fasterxml.jackson.databind.introspect.AnnotationMap)1 Builder (com.google.common.collect.ImmutableList.Builder)1