10
10
import com .fasterxml .jackson .core .*;
11
11
import com .fasterxml .jackson .databind .*;
12
12
import com .fasterxml .jackson .databind .annotation .JacksonStdImpl ;
13
- import com .fasterxml .jackson .databind .introspect .AnnotatedMethod ;
13
+ import com .fasterxml .jackson .databind .introspect .AnnotatedMember ;
14
14
import com .fasterxml .jackson .databind .jsonFormatVisitors .JsonFormatVisitable ;
15
15
import com .fasterxml .jackson .databind .jsonFormatVisitors .JsonFormatVisitorWrapper ;
16
16
import com .fasterxml .jackson .databind .jsonFormatVisitors .JsonStringFormatVisitor ;
38
38
public class JsonValueSerializer
39
39
extends StdSerializer <Object >
40
40
implements ContextualSerializer , JsonFormatVisitable , SchemaAware
41
- {
41
+ {
42
42
/**
43
- * @since 2.8 (was "plain" method before)
43
+ * @since 2.9
44
44
*/
45
- protected final AnnotatedMethod _accessorMethod ;
45
+ protected final AnnotatedMember _accessor ;
46
46
47
47
protected final JsonSerializer <Object > _valueSerializer ;
48
48
@@ -72,10 +72,10 @@ public class JsonValueSerializer
72
72
* to information we need
73
73
*/
74
74
@ SuppressWarnings ("unchecked" )
75
- public JsonValueSerializer (AnnotatedMethod valueMethod , JsonSerializer <?> ser )
75
+ public JsonValueSerializer (AnnotatedMember accessor , JsonSerializer <?> ser )
76
76
{
77
- super (valueMethod .getType ());
78
- _accessorMethod = valueMethod ;
77
+ super (accessor .getType ());
78
+ _accessor = accessor ;
79
79
_valueSerializer = (JsonSerializer <Object >) ser ;
80
80
_property = null ;
81
81
_forceTypeInformation = true ; // gets reconsidered when we are contextualized
@@ -86,7 +86,7 @@ public JsonValueSerializer(JsonValueSerializer src, BeanProperty property,
86
86
JsonSerializer <?> ser , boolean forceTypeInfo )
87
87
{
88
88
super (_notNullClass (src .handledType ()));
89
- _accessorMethod = src ._accessorMethod ;
89
+ _accessor = src ._accessor ;
90
90
_valueSerializer = (JsonSerializer <Object >) ser ;
91
91
_property = property ;
92
92
_forceTypeInformation = forceTypeInfo ;
@@ -128,7 +128,7 @@ public JsonSerializer<?> createContextual(SerializerProvider provider,
128
128
* if not, we don't really know the actual type until we get the instance.
129
129
*/
130
130
// 10-Mar-2010, tatu: Except if static typing is to be used
131
- JavaType t = _accessorMethod .getType ();
131
+ JavaType t = _accessor .getType ();
132
132
if (provider .isEnabled (MapperFeature .USE_STATIC_TYPING ) || t .isFinal ()) {
133
133
// false -> no need to cache
134
134
/* 10-Mar-2010, tatu: Ideally we would actually separate out type
@@ -162,7 +162,7 @@ public JsonSerializer<?> createContextual(SerializerProvider provider,
162
162
public void serialize (Object bean , JsonGenerator gen , SerializerProvider prov ) throws IOException
163
163
{
164
164
try {
165
- Object value = _accessorMethod .getValue (bean );
165
+ Object value = _accessor .getValue (bean );
166
166
if (value == null ) {
167
167
prov .defaultSerializeNull (gen );
168
168
return ;
@@ -179,7 +179,7 @@ public void serialize(Object bean, JsonGenerator gen, SerializerProvider prov) t
179
179
}
180
180
ser .serialize (value , gen , prov );
181
181
} catch (Exception e ) {
182
- wrapAndThrow (prov , e , bean , _accessorMethod .getName () + "()" );
182
+ wrapAndThrow (prov , e , bean , _accessor .getName () + "()" );
183
183
}
184
184
}
185
185
@@ -190,7 +190,7 @@ public void serializeWithType(Object bean, JsonGenerator gen, SerializerProvider
190
190
// Regardless of other parts, first need to find value to serialize:
191
191
Object value = null ;
192
192
try {
193
- value = _accessorMethod .getValue (bean );
193
+ value = _accessor .getValue (bean );
194
194
// and if we got null, can also just write it directly
195
195
if (value == null ) {
196
196
provider .defaultSerializeNull (gen );
@@ -217,7 +217,7 @@ public void serializeWithType(Object bean, JsonGenerator gen, SerializerProvider
217
217
TypeSerializerRerouter rr = new TypeSerializerRerouter (typeSer0 , bean );
218
218
ser .serializeWithType (value , gen , provider , rr );
219
219
} catch (Exception e ) {
220
- wrapAndThrow (provider , e , bean , _accessorMethod .getName () + "()" );
220
+ wrapAndThrow (provider , e , bean , _accessor .getName () + "()" );
221
221
}
222
222
}
223
223
@@ -245,8 +245,8 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t
245
245
*
246
246
* Note that meaning of JsonValue, then, is very different for Enums. Sigh.
247
247
*/
248
- final JavaType type = _accessorMethod .getType ();
249
- Class <?> declaring = _accessorMethod .getDeclaringClass ();
248
+ final JavaType type = _accessor .getType ();
249
+ Class <?> declaring = _accessor .getDeclaringClass ();
250
250
if ((declaring != null ) && declaring .isEnum ()) {
251
251
if (_acceptJsonFormatVisitorForEnum (visitor , typeHint , declaring )) {
252
252
return ;
@@ -285,14 +285,14 @@ protected boolean _acceptJsonFormatVisitorForEnum(JsonFormatVisitorWrapper visit
285
285
// 21-Apr-2016, tatu: This is convoluted to the max, but essentially we
286
286
// call `@JsonValue`-annotated accessor method on all Enum members,
287
287
// so it all "works out". To some degree.
288
- enums .add (String .valueOf (_accessorMethod . callOn (en )));
288
+ enums .add (String .valueOf (_accessor . getValue (en )));
289
289
} catch (Exception e ) {
290
290
Throwable t = e ;
291
291
while (t instanceof InvocationTargetException && t .getCause () != null ) {
292
292
t = t .getCause ();
293
293
}
294
294
ClassUtil .throwIfError (t );
295
- throw JsonMappingException .wrapWithPath (t , en , _accessorMethod .getName () + "()" );
295
+ throw JsonMappingException .wrapWithPath (t , en , _accessor .getName () + "()" );
296
296
}
297
297
}
298
298
stringVisitor .enumTypes (enums );
@@ -324,7 +324,7 @@ protected boolean isNaturalTypeWithStdHandling(Class<?> rawType, JsonSerializer<
324
324
325
325
@ Override
326
326
public String toString () {
327
- return "(@JsonValue serializer for method " + _accessorMethod .getDeclaringClass () + "#" + _accessorMethod .getName () + ")" ;
327
+ return "(@JsonValue serializer for method " + _accessor .getDeclaringClass () + "#" + _accessor .getName () + ")" ;
328
328
}
329
329
330
330
/*
0 commit comments