Skip to content

Commit

Permalink
perf[storage]: catch convert exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Jul 19, 2024
1 parent 1f7b76d commit 0689809
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
return Array.newInstance(componentType, 0);
}
// 如果为json格式,则以json格式解析
if (content.startsWith("[") || content.endsWith("]")) {
return componentType.isPrimitive()
? JsonUtils.string2Object(content, targetType.getObjectType())
: JsonUtils.string2Array(content, componentType);
if (content.startsWith("[") && content.endsWith("]")) {
try {
return componentType.isPrimitive()
? JsonUtils.string2Object(content, targetType.getObjectType())
: JsonUtils.string2Array(content, componentType);

} catch (Exception e) {
}
}
return ConvertUtils.convertToArray(content, componentType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ public Object convert(Object source, @NonNull TypeDescriptor sourceType, TypeDes
} else {
clazz = (Class<?>) type;
}
if (content.startsWith("[") || content.endsWith("]")) {
return Collections.unmodifiableList(JsonUtils.string2List(content, clazz));
if (content.startsWith("[") && content.endsWith("]")) {
try {
return Collections.unmodifiableList(JsonUtils.string2List(content, clazz));
} catch (Exception e) {
}
}
return ConvertUtils.convertToList(content, clazz);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ public Object convert(Object source, @NonNull TypeDescriptor sourceType, TypeDes
} else {
clazz = (Class<?>) type;
}
if (content.startsWith("[") || content.endsWith("]")) {
return Collections.unmodifiableSet(JsonUtils.string2Set(content, clazz));
if (content.startsWith("[") && content.endsWith("]")) {
try {
return Collections.unmodifiableSet(JsonUtils.string2Set(content, clazz));
} catch (Exception e) {
}
}
return ConvertUtils.convertToSet(content, clazz);
}
Expand Down

0 comments on commit 0689809

Please sign in to comment.