|
13 | 13 | package com.zfoo.storage.convert;
|
14 | 14 |
|
15 | 15 | import com.zfoo.protocol.util.StringUtils;
|
| 16 | +import org.springframework.context.ConfigurableApplicationContext; |
16 | 17 | import org.springframework.context.support.ConversionServiceFactoryBean;
|
17 | 18 | import org.springframework.core.convert.ConversionService;
|
18 | 19 | import org.springframework.core.convert.TypeDescriptor;
|
@@ -63,15 +64,16 @@ public static Object convertField(String content, Field field) {
|
63 | 64 |
|
64 | 65 | public static Object convertToArray(String content, Class<?> componentType) {
|
65 | 66 | content = StringUtils.trim(content);
|
66 |
| - // null safe,content为空则返回长度为0的数组 |
67 | 67 | if (StringUtils.isEmpty(content)) {
|
68 | 68 | return Array.newInstance(componentType, 0);
|
69 | 69 | }
|
70 |
| - // 用普通的逗号分隔符解析 |
71 |
| - var list = convertToList(content, componentType); |
72 |
| - Object array = Array.newInstance(componentType, list.size()); |
73 |
| - for (var i = 0; i < list.size(); i++) { |
74 |
| - Array.set(array, i, list.get(i)); |
| 70 | + // Use commas, semicolons, newline separators to parse |
| 71 | + var splits = StringUtils.tokenize(content, ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS); |
| 72 | + Object array = Array.newInstance(componentType, splits.length); |
| 73 | + for (var i = 0; i < splits.length; i++) { |
| 74 | + var split = splits[i]; |
| 75 | + var value = convert(StringUtils.trim(split), componentType); |
| 76 | + Array.set(array, i, value); |
75 | 77 | }
|
76 | 78 | return array;
|
77 | 79 | }
|
|
0 commit comments