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

@@ -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) {
// 默认转换