From f72f1c3727f1ab5e33d67d1bb0b99350d3082006 Mon Sep 17 00:00:00 2001 From: easepan Date: Tue, 10 Nov 2020 11:41:47 +0800 Subject: [PATCH] feat: add alias --- hutool/class.json | 3 ++ hutool/command.json | 7 +++++ hutool/converter.json | 1 + hutool/method/str-util.json | 10 ++++++- .../hutool/converter/ListStringConverter.java | 29 +++++++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/code4everything/hutool/converter/ListStringConverter.java diff --git a/hutool/class.json b/hutool/class.json index 9089238..3ec46c7 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 f5fe9e9..a56d8a0 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 33b2878..9045300 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 9e26dfe..9b0d48d 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 0000000..3007033 --- /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); + } +} -- Gitee