|
1 | 1 | /*
|
2 |
| - * Copyright 2018-2021 the original author or authors. |
| 2 | + * Copyright 2018-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
52 | 52 | *
|
53 | 53 | * @author Mark Paluch
|
54 | 54 | * @author Jens Schauder
|
| 55 | + * @author Chirag Tailor |
55 | 56 | * @see MappingContext
|
56 | 57 | * @see SimpleTypeHolder
|
57 | 58 | * @see CustomConversions
|
@@ -168,7 +169,7 @@ public Object readValue(@Nullable Object value, TypeInformation<?> type) {
|
168 | 169 | return getConversionService().convert(value, sourceDescriptor, targetDescriptor);
|
169 | 170 | }
|
170 | 171 |
|
171 |
| - return getPotentiallyConvertedSimpleRead(value, type.getType()); |
| 172 | + return getPotentiallyConvertedSimpleRead(value, type); |
172 | 173 | }
|
173 | 174 |
|
174 | 175 | /*
|
@@ -235,25 +236,25 @@ private Object getPotentiallyConvertedSimpleWrite(Object value) {
|
235 | 236 | * {@link Enum} handling or returns the value as is.
|
236 | 237 | *
|
237 | 238 | * @param value to be converted. May be {@code null}..
|
238 |
| - * @param target may be {@code null}.. |
| 239 | + * @param type {@link TypeInformation} into which the value is to be converted. Must not be {@code null}. |
239 | 240 | * @return the converted value if a conversion applies or the original value. Might return {@code null}.
|
240 | 241 | */
|
241 | 242 | @Nullable
|
242 | 243 | @SuppressWarnings({ "rawtypes", "unchecked" })
|
243 |
| - private Object getPotentiallyConvertedSimpleRead(@Nullable Object value, @Nullable Class<?> target) { |
244 |
| - |
245 |
| - if (value == null || target == null || ClassUtils.isAssignableValue(target, value)) { |
| 244 | + private Object getPotentiallyConvertedSimpleRead(Object value, TypeInformation<?> type) { |
| 245 | + Class<?> target = type.getType(); |
| 246 | + if (ClassUtils.isAssignableValue(target, value)) { |
246 | 247 | return value;
|
247 | 248 | }
|
248 | 249 |
|
249 | 250 | if (Enum.class.isAssignableFrom(target)) {
|
250 | 251 | return Enum.valueOf((Class<Enum>) target, value.toString());
|
251 | 252 | }
|
252 | 253 |
|
253 |
| - return conversionService.convert(value, target); |
| 254 | + return conversionService.convert(value, TypeDescriptor.forObject(value), createTypeDescriptor(type)); |
254 | 255 | }
|
255 | 256 |
|
256 |
| - protected static TypeDescriptor createTypeDescriptor(TypeInformation<?> type) { |
| 257 | + private static TypeDescriptor createTypeDescriptor(TypeInformation<?> type) { |
257 | 258 |
|
258 | 259 | List<TypeInformation<?>> typeArguments = type.getTypeArguments();
|
259 | 260 | Class<?>[] generics = new Class[typeArguments.size()];
|
|
0 commit comments