|
7 | 7 | import com.fasterxml.jackson.databind.*;
|
8 | 8 | import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
9 | 9 | import com.fasterxml.jackson.databind.introspect.Annotated;
|
| 10 | +import com.fasterxml.jackson.databind.introspect.AnnotatedMember; |
10 | 11 | import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
|
11 | 12 | import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
12 | 13 | import com.fasterxml.jackson.databind.ser.ContextualSerializer;
|
@@ -83,14 +84,17 @@ protected OptionalSerializer withResolved(BeanProperty prop,
|
83 | 84 | public JsonSerializer<?> createContextual(SerializerProvider provider,
|
84 | 85 | BeanProperty property) throws JsonMappingException
|
85 | 86 | {
|
86 |
| - JsonSerializer<?> ser = _valueSerializer; |
| 87 | + JsonSerializer<?> ser = findContentSerializer(provider, property); |
87 | 88 | if (ser == null) {
|
88 |
| - // A few conditions needed to be able to fetch serializer here: |
89 |
| - if (_useStatic(provider, property, _referredType)) { |
90 |
| - ser = _findSerializer(provider, _referredType, property); |
| 89 | + ser = _valueSerializer; |
| 90 | + if (ser == null) { |
| 91 | + // A few conditions needed to be able to fetch serializer here: |
| 92 | + if (_useStatic(provider, property, _referredType)) { |
| 93 | + ser = _findSerializer(provider, _referredType, property); |
| 94 | + } |
| 95 | + } else { |
| 96 | + ser = provider.handlePrimaryContextualization(ser, property); |
91 | 97 | }
|
92 |
| - } else { |
93 |
| - ser = provider.handlePrimaryContextualization(ser, property); |
94 | 98 | }
|
95 | 99 | return withResolved(property, ser, _unwrapper);
|
96 | 100 | }
|
@@ -262,4 +266,24 @@ private final JsonSerializer<Object> _findSerializer(SerializerProvider provider
|
262 | 266 | {
|
263 | 267 | return provider.findTypedValueSerializer(type, true, prop);
|
264 | 268 | }
|
| 269 | + |
| 270 | + // !!! 22-Mar-2016, tatu: Method added in jackson-databind 2.7.4; may be used |
| 271 | + // when we go 2.8 |
| 272 | + protected JsonSerializer<?> findContentSerializer(SerializerProvider serializers, |
| 273 | + BeanProperty property) |
| 274 | + throws JsonMappingException |
| 275 | + { |
| 276 | + if (property != null) { |
| 277 | + // First: if we have a property, may have property-annotation overrides |
| 278 | + AnnotatedMember m = property.getMember(); |
| 279 | + final AnnotationIntrospector intr = serializers.getAnnotationIntrospector(); |
| 280 | + if (m != null) { |
| 281 | + Object serDef = intr.findContentSerializer(m); |
| 282 | + if (serDef != null) { |
| 283 | + return serializers.serializerInstance(m, serDef); |
| 284 | + } |
| 285 | + } |
| 286 | + } |
| 287 | + return null; |
| 288 | + } |
265 | 289 | }
|
0 commit comments