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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations