Skip to content

Commit

Permalink
Merge pull request #100 from ZoneQ/main
Browse files Browse the repository at this point in the history
fix[storage]: json2List Parse bug
  • Loading branch information
jaysunxiao authored May 7, 2024
2 parents c3bb8d0 + 26e4241 commit 2e2083f
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,16 +41,20 @@ public Set<ConvertiblePair> 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));
}
}

0 comments on commit 2e2083f

Please sign in to comment.