Skip to content

Commit

Permalink
fix[storage]: array convert type error
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Jul 19, 2024
1 parent 98d293b commit 891af8f
Showing 1 changed file with 4 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.zfoo.storage.strategy;

import com.zfoo.protocol.util.JsonUtils;
import com.zfoo.protocol.util.StringUtils;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.ConditionalGenericConverter;

Expand All @@ -39,25 +38,9 @@ public Set<ConvertiblePair> getConvertibleTypes() {

@Override
public Object convert(Object source, 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;

String targetClazzName = targetType.getObjectType().getName();
if (targetClazzName.contains(StringUtils.LEFT_SQUARE_BRACKET) || targetClazzName.contains(StringUtils.SEMICOLON)) {
String clazzPath = targetClazzName.substring(2, targetClazzName.length() - 1);
try {
clazz = Class.forName(clazzPath);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
} else {
clazz = targetType.getObjectType();
}

return JsonUtils.string2Array(content, clazz);
String content = (String) source;
return targetType.getType().getComponentType().isPrimitive()
? JsonUtils.string2Object(content, targetType.getObjectType())
: JsonUtils.string2Array(content, targetType.getType().getComponentType());
}
}

0 comments on commit 891af8f

Please sign in to comment.