|
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
|
@@ -148,7 +149,7 @@ public Object readValue(@Nullable Object value, TypeInformation<?> type) {
|
148 | 149 | return getConversionService().convert(value, sourceDescriptor, targetDescriptor);
|
149 | 150 | }
|
150 | 151 |
|
151 |
| - return getPotentiallyConvertedSimpleRead(value, type.getType()); |
| 152 | + return getPotentiallyConvertedSimpleRead(value, type); |
152 | 153 | }
|
153 | 154 |
|
154 | 155 | @Override
|
@@ -211,25 +212,25 @@ private Object getPotentiallyConvertedSimpleWrite(Object value) {
|
211 | 212 | * {@link Enum} handling or returns the value as is.
|
212 | 213 | *
|
213 | 214 | * @param value to be converted. May be {@code null}..
|
214 |
| - * @param target may be {@code null}.. |
| 215 | + * @param type {@link TypeInformation} into which the value is to be converted. Must not be {@code null}. |
215 | 216 | * @return the converted value if a conversion applies or the original value. Might return {@code null}.
|
216 | 217 | */
|
217 | 218 | @Nullable
|
218 | 219 | @SuppressWarnings({ "rawtypes", "unchecked" })
|
219 |
| - private Object getPotentiallyConvertedSimpleRead(@Nullable Object value, @Nullable Class<?> target) { |
220 |
| - |
221 |
| - if (value == null || target == null || ClassUtils.isAssignableValue(target, value)) { |
| 220 | + private Object getPotentiallyConvertedSimpleRead(Object value, TypeInformation<?> type) { |
| 221 | + Class<?> target = type.getType(); |
| 222 | + if (ClassUtils.isAssignableValue(target, value)) { |
222 | 223 | return value;
|
223 | 224 | }
|
224 | 225 |
|
225 | 226 | if (Enum.class.isAssignableFrom(target)) {
|
226 | 227 | return Enum.valueOf((Class<Enum>) target, value.toString());
|
227 | 228 | }
|
228 | 229 |
|
229 |
| - return conversionService.convert(value, target); |
| 230 | + return conversionService.convert(value, TypeDescriptor.forObject(value), createTypeDescriptor(type)); |
230 | 231 | }
|
231 | 232 |
|
232 |
| - protected static TypeDescriptor createTypeDescriptor(TypeInformation<?> type) { |
| 233 | + private static TypeDescriptor createTypeDescriptor(TypeInformation<?> type) { |
233 | 234 |
|
234 | 235 | List<TypeInformation<?>> typeArguments = type.getTypeArguments();
|
235 | 236 | Class<?>[] generics = new Class[typeArguments.size()];
|
|
0 commit comments