add method

This commit is contained in:
Looly 2022-01-13 10:57:33 +08:00
parent f054cef97b
commit f85f29174d
3 changed files with 24 additions and 7 deletions

View File

@ -3,12 +3,13 @@
-------------------------------------------------------------------------------------------------------------
# 5.7.20 (2022-01-12)
# 5.7.20 (2022-01-13)
### 🐣新特性
* 【core 】 增加对null值友好的groupingBy操作的Collector实现可指定map类型pr#498@Gitee
* 【core 】 增加KetamaHashissue#2084@Github
* 【crypto 】 增加SignUtil
* 【json 】 JSONGetter增加getBeanList方法
*
### 🐞Bug修复
* 【core 】 修复setter重载导致匹配错误issue#2082@Github

View File

@ -16,7 +16,6 @@ import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.nio.charset.Charset;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
@ -165,7 +164,7 @@ public class FileWriter extends FileWrapper {
* @return 目标文件
* @throws IORuntimeException IO异常
*/
public <T> File writeLines(Collection<T> list) throws IORuntimeException {
public <T> File writeLines(Iterable<T> list) throws IORuntimeException {
return writeLines(list, false);
}
@ -177,7 +176,7 @@ public class FileWriter extends FileWrapper {
* @return 目标文件
* @throws IORuntimeException IO异常
*/
public <T> File appendLines(Collection<T> list) throws IORuntimeException {
public <T> File appendLines(Iterable<T> list) throws IORuntimeException {
return writeLines(list, true);
}
@ -190,7 +189,7 @@ public class FileWriter extends FileWrapper {
* @return 目标文件
* @throws IORuntimeException IO异常
*/
public <T> File writeLines(Collection<T> list, boolean isAppend) throws IORuntimeException {
public <T> File writeLines(Iterable<T> list, boolean isAppend) throws IORuntimeException {
return writeLines(list, null, isAppend);
}
@ -205,12 +204,13 @@ public class FileWriter extends FileWrapper {
* @throws IORuntimeException IO异常
* @since 3.1.0
*/
public <T> File writeLines(Collection<T> list, LineSeparator lineSeparator, boolean isAppend) throws IORuntimeException {
public <T> File writeLines(Iterable<T> list, LineSeparator lineSeparator, boolean isAppend) throws IORuntimeException {
try (PrintWriter writer = getPrintWriter(isAppend)) {
for (T t : list) {
if (null != t) {
writer.print(t);
printNewLine(writer, lineSeparator);
writer.print(t);
writer.flush();
}
}

View File

@ -9,6 +9,7 @@ import cn.hutool.core.util.StrUtil;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Optional;
/**
@ -113,6 +114,21 @@ public interface JSONGetter<K> extends OptNullBasicTypeFromObjectGetter<K> {
return (null == obj) ? null : obj.toBean(beanType);
}
/**
* 从JSON中直接获取Bean的List列表<br>
* 先获取JSONArray对象然后转为Bean的List
*
* @param <T> Bean类型
* @param key KEY
* @param beanType Bean类型
* @return Bean的List如果值为null或者非JSONObject类型返回null
* @since 5.7.20
*/
default <T> List<T> getBeanList(K key, Class<T> beanType) {
final JSONArray jsonArray = getJSONArray(key);
return (null == jsonArray) ? null : jsonArray.toList(beanType);
}
@Override
default Date getDate(K key, Date defaultValue) {
// 默认转换