From 26e42418518494e472996f29eeab935b66f8116c Mon Sep 17 00:00:00 2001 From: zhenyu <15966826188@163.com> Date: Tue, 7 May 2024 11:45:23 +0800 Subject: [PATCH] fix[storage]: json2List Parse bug --- .../zfoo/storage/strategy/JsonToListConverter.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/storage/src/main/java/com/zfoo/storage/strategy/JsonToListConverter.java b/storage/src/main/java/com/zfoo/storage/strategy/JsonToListConverter.java index 10d25491f..9be8ea057 100644 --- a/storage/src/main/java/com/zfoo/storage/strategy/JsonToListConverter.java +++ b/storage/src/main/java/com/zfoo/storage/strategy/JsonToListConverter.java @@ -16,7 +16,10 @@ import com.zfoo.protocol.util.JsonUtils; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; +import org.springframework.lang.NonNull; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; import java.util.Collections; import java.util.List; import java.util.Set; @@ -38,16 +41,20 @@ public Set getConvertibleTypes() { } @Override - public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public Object convert(Object source, @NonNull TypeDescriptor sourceType, TypeDescriptor targetType) { // String content = (String) source; // return targetType.isPrimitive() ? JsonUtil.string2Object(content, targetType.getObjectType()) // : JsonUtil.string2Array(content, targetType.getType()); Class clazz = null; String content = (String) source; - for (var v : targetType.getResolvableType().getGenerics()){ - clazz = (Class) v.getType(); + Type type = targetType.getResolvableType().getGeneric(0).getType(); + if (type instanceof Class) { + clazz = (Class) type; + } else if (type instanceof ParameterizedType parameterizedType) { + clazz = (Class) parameterizedType.getRawType(); } + return Collections.unmodifiableList(JsonUtils.string2List(content, clazz)); } }