Search in sources :

Example 1 with AnnotatedMember

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

the class ObjectArraySerializer method createContextual.

/*
    /**********************************************************
    /* Post-processing
    /**********************************************************
     */
@Override
public JsonSerializer<?> createContextual(SerializerProvider serializers, BeanProperty property) throws JsonMappingException {
    TypeSerializer vts = _valueTypeSerializer;
    if (vts != null) {
        vts = vts.forProperty(property);
    }
    JsonSerializer<?> ser = null;
    Boolean unwrapSingle = null;
    // First: if we have a property, may have property-annotation overrides
    if (property != null) {
        AnnotatedMember m = property.getMember();
        final AnnotationIntrospector intr = serializers.getAnnotationIntrospector();
        if (m != null) {
            Object serDef = intr.findContentSerializer(m);
            if (serDef != null) {
                ser = serializers.serializerInstance(m, serDef);
            }
        }
    }
    JsonFormat.Value format = findFormatOverrides(serializers, property, handledType());
    if (format != null) {
        unwrapSingle = format.getFeature(JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED);
    }
    if (ser == null) {
        ser = _elementSerializer;
    }
    // [databind#124]: May have a content converter
    ser = findContextualConvertingSerializer(serializers, property, ser);
    if (ser == null) {
        //   we can consider it a static case as well.
        if (_elementType != null) {
            if (_staticTyping && !_elementType.isJavaLangObject()) {
                ser = serializers.findValueSerializer(_elementType, property);
            }
        }
    }
    return withResolved(property, vts, ser, unwrapSingle);
}
Also used : JsonFormat(com.fasterxml.jackson.annotation.JsonFormat) TypeSerializer(com.fasterxml.jackson.databind.jsontype.TypeSerializer) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember)

Example 2 with AnnotatedMember

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

the class StaticListSerializerBase method createContextual.

/*
    /**********************************************************
    /* Post-processing
    /**********************************************************
     */
@SuppressWarnings("unchecked")
@Override
public JsonSerializer<?> createContextual(SerializerProvider serializers, BeanProperty property) throws JsonMappingException {
    JsonSerializer<?> ser = null;
    Boolean unwrapSingle = null;
    if (property != null) {
        final AnnotationIntrospector intr = serializers.getAnnotationIntrospector();
        AnnotatedMember m = property.getMember();
        if (m != null) {
            Object serDef = intr.findContentSerializer(m);
            if (serDef != null) {
                ser = serializers.serializerInstance(m, serDef);
            }
        }
    }
    JsonFormat.Value format = findFormatOverrides(serializers, property, handledType());
    if (format != null) {
        unwrapSingle = format.getFeature(JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED);
    }
    // [databind#124]: May have a content converter
    ser = findContextualConvertingSerializer(serializers, property, ser);
    if (ser == null) {
        ser = serializers.findValueSerializer(String.class, property);
    }
    // Optimization: default serializer just writes String, so we can avoid a call:
    if (isDefaultSerializer(ser)) {
        if (unwrapSingle == _unwrapSingle) {
            return this;
        }
        return _withResolved(property, unwrapSingle);
    }
    // note: will never have TypeSerializer, because Strings are "natural" type
    return new CollectionSerializer(serializers.constructType(String.class), true, /*TypeSerializer*/
    null, (JsonSerializer<Object>) ser);
}
Also used : JsonFormat(com.fasterxml.jackson.annotation.JsonFormat) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember)

Example 3 with AnnotatedMember

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

the class StdSerializer method findConvertingContentSerializer.

/**
     * @deprecated Since 2.9 use {link {@link #findContextualConvertingSerializer} instead
     */
@Deprecated
protected JsonSerializer<?> findConvertingContentSerializer(SerializerProvider provider, BeanProperty prop, JsonSerializer<?> existingSerializer) throws JsonMappingException {
    final AnnotationIntrospector intr = provider.getAnnotationIntrospector();
    if (_neitherNull(intr, prop)) {
        AnnotatedMember m = prop.getMember();
        if (m != null) {
            Object convDef = intr.findSerializationContentConverter(m);
            if (convDef != null) {
                Converter<Object, Object> conv = provider.converterInstance(prop.getMember(), convDef);
                JavaType delegateType = conv.getOutputType(provider.getTypeFactory());
                // [databind#731]: Should skip if nominally java.lang.Object
                if ((existingSerializer == null) && !delegateType.isJavaLangObject()) {
                    existingSerializer = provider.findValueSerializer(delegateType);
                }
                return new StdDelegatingSerializer(conv, delegateType, existingSerializer);
            }
        }
    }
    return existingSerializer;
}
Also used : AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember)

Example 4 with AnnotatedMember

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

the class AsArraySerializerBase method createContextual.

/*
    /**********************************************************
    /* Post-processing
    /**********************************************************
     */
/**
     * This method is needed to resolve contextual annotations like
     * per-property overrides, as well as do recursive call
     * to <code>createContextual</code> of content serializer, if
     * known statically.
     */
@Override
public JsonSerializer<?> createContextual(SerializerProvider serializers, BeanProperty property) throws JsonMappingException {
    TypeSerializer typeSer = _valueTypeSerializer;
    if (typeSer != null) {
        typeSer = typeSer.forProperty(property);
    }
    JsonSerializer<?> ser = null;
    Boolean unwrapSingle = null;
    if (property != null) {
        final AnnotationIntrospector intr = serializers.getAnnotationIntrospector();
        AnnotatedMember m = property.getMember();
        if (m != null) {
            Object serDef = intr.findContentSerializer(m);
            if (serDef != null) {
                ser = serializers.serializerInstance(m, serDef);
            }
        }
    }
    JsonFormat.Value format = findFormatOverrides(serializers, property, handledType());
    if (format != null) {
        unwrapSingle = format.getFeature(JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED);
    }
    if (ser == null) {
        ser = _elementSerializer;
    }
    // 18-Feb-2013, tatu: May have a content converter:
    ser = findContextualConvertingSerializer(serializers, property, ser);
    if (ser == null) {
        //   we can consider it a static case as well.
        if (_elementType != null) {
            if (_staticTyping && !_elementType.isJavaLangObject()) {
                ser = serializers.findValueSerializer(_elementType, property);
            }
        }
    }
    if ((ser != _elementSerializer) || (property != _property) || (_valueTypeSerializer != typeSer) || (_unwrapSingle != unwrapSingle)) {
        return withResolved(property, typeSer, ser, unwrapSingle);
    }
    return this;
}
Also used : JsonFormat(com.fasterxml.jackson.annotation.JsonFormat) TypeSerializer(com.fasterxml.jackson.databind.jsontype.TypeSerializer) AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember)

Example 5 with AnnotatedMember

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

the class StringArraySerializer method createContextual.

/*
    /**********************************************************
    /* Post-processing
    /**********************************************************
     */
@Override
public JsonSerializer<?> createContextual(SerializerProvider provider, BeanProperty property) throws JsonMappingException {
    /* 29-Sep-2012, tatu: Actually, we need to do much more contextual
         *    checking here since we finally know for sure the property,
         *    and it may have overrides
         */
    JsonSerializer<?> ser = null;
    // First: if we have a property, may have property-annotation overrides
    if (property != null) {
        final AnnotationIntrospector ai = provider.getAnnotationIntrospector();
        AnnotatedMember m = property.getMember();
        if (m != null) {
            Object serDef = ai.findContentSerializer(m);
            if (serDef != null) {
                ser = provider.serializerInstance(m, serDef);
            }
        }
    }
    // but since formats have both property overrides and global per-type defaults,
    // need to do that separately
    Boolean unwrapSingle = findFormatFeature(provider, property, String[].class, JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED);
    if (ser == null) {
        ser = _elementSerializer;
    }
    // May have a content converter
    ser = findContextualConvertingSerializer(provider, property, ser);
    if (ser == null) {
        ser = provider.findValueSerializer(String.class, property);
    }
    // Optimization: default serializer just writes String, so we can avoid a call:
    if (isDefaultSerializer(ser)) {
        ser = null;
    }
    // note: will never have TypeSerializer, because Strings are "natural" type
    if ((ser == _elementSerializer) && (unwrapSingle == _unwrapSingle)) {
        return this;
    }
    return new StringArraySerializer(this, property, ser, unwrapSingle);
}
Also used : AnnotatedMember(com.fasterxml.jackson.databind.introspect.AnnotatedMember)

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