9
9
import com .fasterxml .jackson .databind .*;
10
10
import com .fasterxml .jackson .databind .cfg .HandlerInstantiator ;
11
11
import com .fasterxml .jackson .databind .introspect .Annotated ;
12
+ import com .fasterxml .jackson .databind .introspect .BeanPropertyDefinition ;
12
13
import com .fasterxml .jackson .databind .jsonFormatVisitors .JsonFormatVisitorWrapper ;
13
14
import com .fasterxml .jackson .databind .jsonschema .SchemaAware ;
14
15
import com .fasterxml .jackson .databind .jsontype .TypeSerializer ;
@@ -100,7 +101,8 @@ public DefaultSerializerProvider copy() {
100
101
*/
101
102
102
103
@ Override
103
- public JsonSerializer <Object > serializerInstance (Annotated annotated , Object serDef ) throws JsonMappingException
104
+ public JsonSerializer <Object > serializerInstance (Annotated annotated , Object serDef )
105
+ throws JsonMappingException
104
106
{
105
107
if (serDef == null ) {
106
108
return null ;
@@ -110,11 +112,11 @@ public JsonSerializer<Object> serializerInstance(Annotated annotated, Object ser
110
112
if (serDef instanceof JsonSerializer ) {
111
113
ser = (JsonSerializer <?>) serDef ;
112
114
} else {
113
- /* Alas, there's no way to force return type of "either class
114
- * X or Y" -- need to throw an exception after the fact
115
- */
115
+ // Alas, there's no way to force return type of "either class
116
+ // X or Y" -- need to throw an exception after the fact
116
117
if (!(serDef instanceof Class )) {
117
- throw new IllegalStateException ("AnnotationIntrospector returned serializer definition of type "
118
+ reportBadDefinition (annotated .getType (),
119
+ "AnnotationIntrospector returned serializer definition of type "
118
120
+serDef .getClass ().getName ()+"; expected type JsonSerializer or Class<JsonSerializer> instead" );
119
121
}
120
122
Class <?> serClass = (Class <?>)serDef ;
@@ -123,7 +125,8 @@ public JsonSerializer<Object> serializerInstance(Annotated annotated, Object ser
123
125
return null ;
124
126
}
125
127
if (!JsonSerializer .class .isAssignableFrom (serClass )) {
126
- throw new IllegalStateException ("AnnotationIntrospector returned Class "
128
+ reportBadDefinition (annotated .getType (),
129
+ "AnnotationIntrospector returned Class "
127
130
+serClass .getName ()+"; expected Class<JsonSerializer>" );
128
131
}
129
132
HandlerInstantiator hi = _config .getHandlerInstantiator ();
@@ -136,6 +139,22 @@ public JsonSerializer<Object> serializerInstance(Annotated annotated, Object ser
136
139
return (JsonSerializer <Object >) _handleResolvable (ser );
137
140
}
138
141
142
+ @ Override
143
+ public Object includeFilterInstance (BeanPropertyDefinition forProperty ,
144
+ Class <?> filterClass )
145
+ {
146
+ if (filterClass == null ) {
147
+ return null ;
148
+ }
149
+ HandlerInstantiator hi = _config .getHandlerInstantiator ();
150
+ Object filter = (hi == null ) ? null : hi .includeFilterInstance (_config , forProperty , filterClass );
151
+ if (filter == null ) {
152
+ filter = (JsonSerializer <?>) ClassUtil .createInstance (filterClass ,
153
+ _config .canOverrideAccessModifiers ());
154
+ }
155
+ return filter ;
156
+ }
157
+
139
158
/*
140
159
/**********************************************************
141
160
/* Object Id handling
0 commit comments