44import com .fasterxml .jackson .databind .DeserializationFeature ;
55import com .fasterxml .jackson .databind .JavaType ;
66import com .fasterxml .jackson .databind .ObjectMapper ;
7+ import com .fasterxml .jackson .databind .type .TypeFactory ;
78import com .fasterxml .jackson .databind .util .ByteBufferBackedInputStream ;
89import lombok .Setter ;
910import lombok .SneakyThrows ;
@@ -34,9 +35,9 @@ public class JsonValueCodec implements ValueCodec<Object, Object> {
3435
3536 static {
3637 defaultMapper = new ObjectMapper ()
37- .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false )
38- .setDefaultPropertyInclusion (JsonInclude .Include .NON_NULL )
39- .setTimeZone (TimeZone .getDefault ());
38+ .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false )
39+ .setDefaultPropertyInclusion (JsonInclude .Include .NON_NULL )
40+ .setTimeZone (TimeZone .getDefault ());
4041 }
4142
4243 private final JavaType jacksonType ;
@@ -51,48 +52,44 @@ public static JsonValueCodec of(Class<?> targetType) {
5152 }
5253
5354 public static JsonValueCodec ofCollection (Class <? extends Collection > targetType
54- , Class <?> elementType ) {
55+ , Class <?> elementType ) {
5556 return new JsonValueCodec (targetType , defaultMapper
56- .getTypeFactory ()
57- .constructCollectionType (targetType , elementType ));
57+ .getTypeFactory ()
58+ .constructCollectionType (targetType , elementType ));
5859 }
5960
6061 public static JsonValueCodec ofMap (Class <? extends Map > targetType , Class <?> keyType , Class <?> valueType ) {
6162 return new JsonValueCodec (targetType , defaultMapper .getTypeFactory ()
6263 .constructMapType (targetType , keyType , valueType ));
6364 }
6465
66+ @ SuppressWarnings ("all" )
6567 public static JsonValueCodec ofField (Field field ) {
6668 Class type = field .getType ();
6769 Class targetType = type ;
6870 Type genericType = field .getGenericType ();
6971 JavaType jacksonType = null ;
7072
7173 if (type == Mono .class || type == Flux .class ) {
72- targetType = (Class ) ((ParameterizedType ) genericType ).getActualTypeArguments ()[0 ];
74+ targetType = (Class <?> ) ((ParameterizedType ) genericType ).getActualTypeArguments ()[0 ];
7375 }
76+ TypeFactory factory = defaultMapper .getTypeFactory ();
7477 if (Map .class .isAssignableFrom (targetType )) {
7578 if (genericType instanceof ParameterizedType ) {
7679 Type [] types = ((ParameterizedType ) genericType ).getActualTypeArguments ();
77- jacksonType = defaultMapper
78- .getTypeFactory ()
79- .constructMapType (targetType , (Class ) types [0 ], (Class ) types [1 ]);
80+ jacksonType = factory .constructMapType (targetType , factory .constructType (types [0 ]), factory .constructType (types [1 ]));
8081 }
8182
8283 } else if (Collection .class .isAssignableFrom (targetType )) {
8384 if (genericType instanceof ParameterizedType ) {
8485 Type [] types = ((ParameterizedType ) genericType ).getActualTypeArguments ();
85- jacksonType = defaultMapper
86- .getTypeFactory ()
87- .constructCollectionType (targetType , (Class ) types [0 ]);
86+ jacksonType = factory .constructCollectionType (targetType , factory .constructType (types [0 ]));
8887 }
8988 } else if (targetType .isArray ()) {
90- jacksonType = defaultMapper
91- .getTypeFactory ()
92- .constructArrayType (targetType .getComponentType ());
89+ jacksonType = factory .constructArrayType (targetType .getComponentType ());
9390 }
9491 if (jacksonType == null ) {
95- jacksonType = defaultMapper . getTypeFactory () .constructType (targetType );
92+ jacksonType = factory .constructType (targetType );
9693 }
9794
9895 return new JsonValueCodec (type , jacksonType );
0 commit comments