Search in sources :

Example 6 with AnnotatedMember

use of com.fasterxml.jackson.databind.introspect.AnnotatedMember in project jackson-databind by FasterXML.

the class MapDeserializer method createContextual.

/**
     * Method called to finalize setup of this deserializer,
     * when it is known for which property deserializer is needed for.
     */
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException {
    KeyDeserializer keyDeser = _keyDeserializer;
    if (keyDeser == null) {
        keyDeser = ctxt.findKeyDeserializer(_containerType.getKeyType(), property);
    } else {
        if (keyDeser instanceof ContextualKeyDeserializer) {
            keyDeser = ((ContextualKeyDeserializer) keyDeser).createContextual(ctxt, property);
        }
    }
    JsonDeserializer<?> valueDeser = _valueDeserializer;
    // [databind#125]: May have a content converter
    if (property != null) {
        valueDeser = findConvertingContentDeserializer(ctxt, property, valueDeser);
    }
    final JavaType vt = _containerType.getContentType();
    if (valueDeser == null) {
        valueDeser = ctxt.findContextualValueDeserializer(vt, property);
    } else {
        // if directly assigned, probably not yet contextual, so:
        valueDeser = ctxt.handleSecondaryContextualization(valueDeser, property, vt);
    }
    TypeDeserializer vtd = _valueTypeDeserializer;
    if (vtd != null) {
        vtd = vtd.forProperty(property);
    }
    Set<String> ignored = _ignorableProperties;
    AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
    if (intr != null && property != null) {
        AnnotatedMember member = property.getMember();
        if (member != null) {
            JsonIgnoreProperties.Value ignorals = intr.findPropertyIgnorals(member);
            if (ignorals != null) {
                Set<String> ignoresToAdd = ignorals.findIgnoredForDeserialization();
                if (!ignoresToAdd.isEmpty()) {
                    ignored = (ignored == null) ? new HashSet<String>() : new HashSet<String>(ignored);
                    for (String str : ignoresToAdd) {
                        ignored.add(str);
                    }
                }
            }
        }
    }
    return withResolved(keyDeser, vtd, valueDeser, findContentNullProvider(ctxt, property, valueDeser), ignored);
}
Also used : AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember) TypeDeserializer(com.fasterxml.jackson.databind.jsontype.TypeDeserializer) JsonIgnoreProperties(com.fasterxml.jackson.annotation.JsonIgnoreProperties)

Example 7 with AnnotatedMember

use of com.fasterxml.jackson.databind.introspect.AnnotatedMember in project candlepin by candlepin.

the class CandlepinSwaggerModelConverter method parseProperty.

private void parseProperty(ModelConverterContext context, boolean isNested, final BeanDescription beanDesc, Set<String> propertiesToIgnore, List<Property> props, BeanPropertyDefinition propDef) {
    Property property = null;
    String propName = propDef.getName();
    Annotation[] annotations = null;
    propName = getPropName(propDef, propName);
    PropertyMetadata md = propDef.getMetadata();
    boolean hasSetter = false, hasGetter = false;
    if (propDef.getSetter() == null) {
        hasSetter = false;
    } else {
        hasSetter = true;
    }
    if (propDef.getGetter() != null) {
        JsonProperty pd = propDef.getGetter().getAnnotation(JsonProperty.class);
        if (pd != null) {
            hasGetter = true;
        }
    }
    Boolean isReadOnly = null;
    if (!hasSetter & hasGetter) {
        isReadOnly = Boolean.TRUE;
    } else {
        isReadOnly = Boolean.FALSE;
    }
    final AnnotatedMember member = propDef.getPrimaryMember();
    if (member != null && !propertiesToIgnore.contains(propName) && /**
     * If the owning type is nested than we should include only those
     * fields that have the Hateoas annotation.
     */
    !(isNested && !member.hasAnnotation(HateoasInclude.class))) {
        List<Annotation> annotationList = new ArrayList<>();
        for (Annotation a : member.annotations()) {
            annotationList.add(a);
        }
        annotations = annotationList.toArray(new Annotation[annotationList.size()]);
        ApiModelProperty mp = member.getAnnotation(ApiModelProperty.class);
        if (mp != null && mp.readOnly()) {
            isReadOnly = mp.readOnly();
        }
        Type nested = null;
        JavaType propType = member.getType(beanDesc.bindingsForBeanType());
        JsonFilter jsonFilter = propType.getRawClass().getAnnotation(JsonFilter.class);
        /**
         * At this point the propType is a type of some nested field of the
         * type that is being processed. The condition checks if this
         * particular type should have Hateoas serialization enabled. In
         * other words, if we should create a new Nested* model.
         */
        if (jsonFilter != null && (jsonFilter.value().equals("ConsumerFilter") || jsonFilter.value().equals("EntitlementFilter") || jsonFilter.value().equals("OwnerFilter") || jsonFilter.value().equals("GuestFilter"))) {
            if (!nestedJavaTypes.containsKey(propType)) {
                nestedJavaTypes.put(propType, new NestedComplexType(propType));
            }
            nested = nestedJavaTypes.get(propType);
        } else {
            nested = propType;
        }
        // allow override of name from annotation
        if (mp != null && !mp.name().isEmpty()) {
            propName = mp.name();
        }
        if (mp != null && !mp.dataType().isEmpty()) {
            property = resolveApiAnnotated(context, property, annotations, mp, propType);
        }
        // no property from override, construct from propType
        if (property == null) {
            if (mp != null && StringUtils.isNotEmpty(mp.reference())) {
                property = new RefProperty(mp.reference());
            } else if (member.getAnnotation(JsonIdentityInfo.class) != null) {
                property = GeneratorWrapper.processJsonIdentity(propType, context, pMapper, member.getAnnotation(JsonIdentityInfo.class), member.getAnnotation(JsonIdentityReference.class));
            }
            if (property == null) {
                property = context.resolveProperty(nested, annotations);
            }
        }
        if (property != null) {
            addMetadataToProperty(property, propName, md, isReadOnly, member, mp);
            applyBeanValidatorAnnotations(property, annotations);
            props.add(property);
        }
    }
}
Also used : ApiModelProperty(io.swagger.annotations.ApiModelProperty) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) JsonIdentityReference(com.fasterxml.jackson.annotation.JsonIdentityReference) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) RefProperty(io.swagger.models.properties.RefProperty) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) Type(java.lang.reflect.Type) JavaType(com.fasterxml.jackson.databind.JavaType) PrimitiveType(io.swagger.util.PrimitiveType) JavaType(com.fasterxml.jackson.databind.JavaType) JsonIdentityInfo(com.fasterxml.jackson.annotation.JsonIdentityInfo) JsonFilter(com.fasterxml.jackson.annotation.JsonFilter) PropertyMetadata(com.fasterxml.jackson.databind.PropertyMetadata) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) UUIDProperty(io.swagger.models.properties.UUIDProperty) ApiModelProperty(io.swagger.annotations.ApiModelProperty) AbstractNumericProperty(io.swagger.models.properties.AbstractNumericProperty) RefProperty(io.swagger.models.properties.RefProperty) IntegerProperty(io.swagger.models.properties.IntegerProperty) HateoasInclude(org.candlepin.common.jackson.HateoasInclude)

Example 8 with AnnotatedMember

use of com.fasterxml.jackson.databind.introspect.AnnotatedMember in project fabric8 by fabric8io.

the class BeanValidationAnnotationIntrospector method hasIgnoreMarker.

@Override
public boolean hasIgnoreMarker(AnnotatedMember m) {
    Member member = m.getMember();
    int modifiers = member.getModifiers();
    if (Modifier.isTransient(modifiers)) {
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Ignoring transient member " + m);
        }
        return true;
    } else if (m instanceof AnnotatedMethod) {
        AnnotatedMethod method = (AnnotatedMethod) m;
        String methodName = method.getName();
        // lets see if there is a transient field of the same name as the getter
        if (methodName.startsWith("get") && method.getParameterCount() == 0) {
            String fieldName = Introspector.decapitalize(methodName.substring(3));
            Class<?> declaringClass = method.getDeclaringClass();
            Field field = findField(fieldName, declaringClass);
            if (field != null) {
                int fieldModifiers = field.getModifiers();
                if (Modifier.isTransient(fieldModifiers)) {
                    LOG.fine("Ignoring member " + m + " due to transient field called " + fieldName);
                    return true;
                }
            }
        }
    }
    return super.hasIgnoreMarker(m);
}
Also used : Field(java.lang.reflect.Field) AnnotatedMethod(com.fasterxml.jackson.databind.introspect.AnnotatedMethod) Member(java.lang.reflect.Member) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember)

Example 9 with AnnotatedMember

use of com.fasterxml.jackson.databind.introspect.AnnotatedMember in project beam by apache.

the class PipelineOptionsFactory method computeCustomSerializerForMethod.

private static Optional<JsonSerializer<Object>> computeCustomSerializerForMethod(Method method) {
    try {
        BeanProperty prop = createBeanProperty(method);
        AnnotatedMember annotatedMethod = prop.getMember();
        Object maybeSerializerClass = SERIALIZER_PROVIDER.getAnnotationIntrospector().findSerializer(annotatedMethod);
        return Optional.fromNullable(SERIALIZER_PROVIDER.serializerInstance(annotatedMethod, maybeSerializerClass));
    } catch (JsonMappingException e) {
        throw new RuntimeException(e);
    }
}
Also used : JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember) BeanProperty(com.fasterxml.jackson.databind.BeanProperty)

Example 10 with AnnotatedMember

use of com.fasterxml.jackson.databind.introspect.AnnotatedMember in project zm-mailbox by Zimbra.

the class ZimbraBeanSerializerModifier method changeProperties.

/*
    /**********************************************************
    /* Overridden methods
    /**********************************************************
     */
/**
 * First thing to do is to find annotations regarding XML serialization,
 * and wrap collection serializers.
 */
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
    AnnotationIntrospector intr = config.getAnnotationIntrospector();
    for (int i = 0, len = beanProperties.size(); i < len; ++i) {
        BeanPropertyWriter bpw = beanProperties.get(i);
        final AnnotatedMember member = bpw.getMember();
        NameInfo nameInfo = new NameInfo(intr, member, bpw.getName());
        if (!nameInfo.needSpecialHandling()) {
            continue;
        }
        beanProperties.set(i, new ZimbraBeanPropertyWriter(bpw, nameInfo));
    }
    return beanProperties;
}
Also used : AnnotationIntrospector(com.fasterxml.jackson.databind.AnnotationIntrospector) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember) BeanPropertyWriter(com.fasterxml.jackson.databind.ser.BeanPropertyWriter)

Aggregations

AnnotatedMember (com.fasterxml.jackson.databind.introspect.AnnotatedMember)22 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)5 JsonFormat (com.fasterxml.jackson.annotation.JsonFormat)4 JsonIgnoreProperties (com.fasterxml.jackson.annotation.JsonIgnoreProperties)4 JsonIdentityInfo (com.fasterxml.jackson.annotation.JsonIdentityInfo)3 JsonIdentityReference (com.fasterxml.jackson.annotation.JsonIdentityReference)3 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)3 JavaType (com.fasterxml.jackson.databind.JavaType)3 PropertyMetadata (com.fasterxml.jackson.databind.PropertyMetadata)3 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)3 Annotation (java.lang.annotation.Annotation)3 Member (java.lang.reflect.Member)3 ArrayList (java.util.ArrayList)3 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)2 JsonTypeInfo (com.fasterxml.jackson.annotation.JsonTypeInfo)2 JsonUnwrapped (com.fasterxml.jackson.annotation.JsonUnwrapped)2 AnnotationIntrospector (com.fasterxml.jackson.databind.AnnotationIntrospector)2 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)2 BeanProperty (com.fasterxml.jackson.databind.BeanProperty)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2