diff --git a/hutool/class.json b/hutool/class.json index 9089238b0aacdeee4e82f1afe5f80c3f5e39fba8..3ec46c7c980f864bc721068d03f2def7ffe00380 100644 --- a/hutool/class.json +++ b/hutool/class.json @@ -122,5 +122,8 @@ }, "pinyin": { "clazz": "cn.hutool.extra.pinyin.PinyinUtil" + }, + "list": { + "clazz": "cn.hutool.core.collection.ListUtil" } } \ No newline at end of file diff --git a/hutool/command.json b/hutool/command.json index f5fe9e90a44f8a428777bd4ae5d72e0db10f0c52..a56d8a0d852a7a614664e4bf22e6c8adfcaa6f2c 100644 --- a/hutool/command.json +++ b/hutool/command.json @@ -250,5 +250,12 @@ "paramTypes": [ "java.util.Date" ] + }, + "split": { + "method": "cn.hutool.core.util.StrUtil#splitTrim", + "paramTypes": [ + "java.lang.CharSequence", + "java.lang.CharSequence" + ] } } \ No newline at end of file diff --git a/hutool/converter.json b/hutool/converter.json index 33b2878cda1302fca4b4c0882c05a1103f6bf989..9045300a2d31c31ae665d2d916807459e0aa5f8f 100644 --- a/hutool/converter.json +++ b/hutool/converter.json @@ -1,4 +1,5 @@ { + /*"java.util.List": "org.code4everything.hutool.converter.ListStringConverter",*/ "cn.hutool.core.date.Week": "org.code4everything.hutool.converter.WeekConverter", "java.io.File": "org.code4everything.hutool.converter.FileConverter", "java.nio.charset.Charset": "org.code4everything.hutool.converter.CharsetConverter", diff --git a/hutool/method/str-util.json b/hutool/method/str-util.json index 9e26dfeeb6e641a33dae4961196235bdb965b21b..9b0d48d82d61c3e0d1e31f3a87a70ab4d02b01db 100644 --- a/hutool/method/str-util.json +++ b/hutool/method/str-util.json @@ -1 +1,9 @@ -{} \ No newline at end of file +{ + "split": { + "methodName": "splitTrim", + "paramTypes": [ + "java.lang.CharSequence", + "java.lang.CharSequence" + ] + } +} \ No newline at end of file diff --git a/src/main/java/org/code4everything/hutool/converter/ListStringConverter.java b/src/main/java/org/code4everything/hutool/converter/ListStringConverter.java new file mode 100644 index 0000000000000000000000000000000000000000..3007033a7d5fbdfeea9b623cecbe700568b91001 --- /dev/null +++ b/src/main/java/org/code4everything/hutool/converter/ListStringConverter.java @@ -0,0 +1,29 @@ +package org.code4everything.hutool.converter; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import org.code4everything.hutool.Converter; + +import java.util.Collections; +import java.util.List; + +/** + * @author pantao + * @since 2020/11/10 + */ +public class ListStringConverter implements Converter> { + + @Override + public List string2Object(String string) { + if (StrUtil.isEmpty(string)) { + return Collections.emptyList(); + } + return StrUtil.splitTrim(StrUtil.strip(string, "[", "]"), ","); + } + + @Override + public String object2String(Object object) { + return object instanceof List ? JSON.toJSONString(object) : ObjectUtil.toString(object); + } +}