mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix bugs
This commit is contained in:
parent
825b5ea1b4
commit
abdedf6822
@ -3,7 +3,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.6.1 (2021-03-16)
|
||||
# 5.6.1 (2021-03-18)
|
||||
|
||||
### 新特性
|
||||
* 【crypto 】 SecureUtil去除final修饰符(issue#1474@Github)
|
||||
@ -11,10 +11,13 @@
|
||||
* 【core 】 新增函数式懒加载加载器(pr#275@Gitee)
|
||||
* 【http 】 UserAgentUtil增加miniProgram判断(issue#1475@Github)
|
||||
* 【db 】 增加Ignite数据库驱动识别
|
||||
* 【core 】 DateUtil.parse支持带毫秒的UTC时间
|
||||
|
||||
### Bug修复
|
||||
* 【core 】 修复IoUtil.readBytes的FileInputStream中isClose参数失效问题(issue#I3B7UD@Gitee)
|
||||
* 【core 】 修复DataUnit中KB不大写的问题
|
||||
* 【json 】 修复JSONUtil.getByPath类型错误问题(issue#I3BSDF@Gitee)
|
||||
* 【core 】 修复BeanUtil.toBean提供null未返回null的问题(issue#I3BQPV@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -544,6 +544,9 @@ public class BeanUtil {
|
||||
* @since 5.2.4
|
||||
*/
|
||||
public static <T> T toBean(Object source, Class<T> clazz, CopyOptions options) {
|
||||
if(null == source){
|
||||
return null;
|
||||
}
|
||||
final T target = ReflectUtil.newInstanceIfPossible(clazz);
|
||||
copyProperties(source, target, options);
|
||||
return target;
|
||||
@ -559,6 +562,9 @@ public class BeanUtil {
|
||||
* @return Bean
|
||||
*/
|
||||
public static <T> T toBean(Class<T> beanClass, ValueProvider<String> valueProvider, CopyOptions copyOptions) {
|
||||
if (null == beanClass || null == valueProvider) {
|
||||
return null;
|
||||
}
|
||||
return fillBean(ReflectUtil.newInstanceIfPossible(beanClass), valueProvider, copyOptions);
|
||||
}
|
||||
|
||||
@ -600,6 +606,9 @@ public class BeanUtil {
|
||||
* @return Map
|
||||
*/
|
||||
public static Map<String, Object> beanToMap(Object bean, boolean isToUnderlineCase, boolean ignoreNullValue) {
|
||||
if (null == bean) {
|
||||
return null;
|
||||
}
|
||||
return beanToMap(bean, new LinkedHashMap<>(), isToUnderlineCase, ignoreNullValue);
|
||||
}
|
||||
|
||||
@ -614,7 +623,7 @@ public class BeanUtil {
|
||||
* @since 3.2.3
|
||||
*/
|
||||
public static Map<String, Object> beanToMap(Object bean, Map<String, Object> targetMap, final boolean isToUnderlineCase, boolean ignoreNullValue) {
|
||||
if (bean == null) {
|
||||
if (null == bean) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -639,7 +648,7 @@ public class BeanUtil {
|
||||
* @since 4.0.5
|
||||
*/
|
||||
public static Map<String, Object> beanToMap(Object bean, Map<String, Object> targetMap, boolean ignoreNullValue, Editor<String> keyEditor) {
|
||||
if (bean == null) {
|
||||
if (null == bean) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -200,6 +200,15 @@ public class DatePattern {
|
||||
*/
|
||||
public static final FastDateFormat UTC_SIMPLE_FORMAT = FastDateFormat.getInstance(UTC_SIMPLE_PATTERN, TimeZone.getTimeZone("UTC"));
|
||||
|
||||
/**
|
||||
* UTC时间:yyyy-MM-dd'T'HH:mm:ss.SSS
|
||||
*/
|
||||
public static final String UTC_SIMPLE_MS_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS";
|
||||
/**
|
||||
* UTC时间{@link FastDateFormat}:yyyy-MM-dd'T'HH:mm:ss.SSS
|
||||
*/
|
||||
public static final FastDateFormat UTC_SIMPLE_MS_FORMAT = FastDateFormat.getInstance(UTC_SIMPLE_MS_PATTERN, TimeZone.getTimeZone("UTC"));
|
||||
|
||||
/**
|
||||
* UTC时间:yyyy-MM-dd'T'HH:mm:ss'Z'
|
||||
*/
|
||||
|
@ -836,6 +836,9 @@ public class DateUtil extends CalendarUtil {
|
||||
} else if (length == DatePattern.UTC_SIMPLE_PATTERN.length() - 2) {
|
||||
// 格式类似:2018-09-13T05:34:31
|
||||
return parse(utcString, DatePattern.UTC_SIMPLE_FORMAT);
|
||||
} else if (StrUtil.contains(utcString, CharUtil.DOT)){
|
||||
// 可能为: 2021-03-17T06:31:33.99
|
||||
return parse(utcString, DatePattern.UTC_SIMPLE_MS_FORMAT);
|
||||
}
|
||||
}
|
||||
// 没有更多匹配的时间格式
|
||||
|
@ -550,6 +550,13 @@ public class DateUtilTest {
|
||||
assert dt != null;
|
||||
dateStr = dt.toString(simpleDateFormat);
|
||||
Assert.assertEquals("2018-09-13 13:34:39.999", dateStr);
|
||||
|
||||
// 使用UTC时区
|
||||
dateStr1 = "2018-09-13T13:34:39.99";
|
||||
dt = DateUtil.parse(dateStr1);
|
||||
assert dt != null;
|
||||
dateStr = dt.toString();
|
||||
Assert.assertEquals("2018-09-13 13:34:39", dateStr);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -39,6 +39,12 @@ public class PinyinUtilTest {
|
||||
Assert.assertEquals("h, s, d, y, g", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstLetterTest2(){
|
||||
final String result = PinyinUtil.getFirstLetter("崞阳", ", ");
|
||||
Assert.assertEquals("g, y", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFirstLetterByPinyin4jTest(){
|
||||
final Pinyin4jEngine engine = new Pinyin4jEngine();
|
||||
|
@ -543,7 +543,7 @@ public class JSONUtil {
|
||||
* @see JSON#getByPath(String)
|
||||
*/
|
||||
public static Object getByPath(JSON json, String expression) {
|
||||
return (null == json || StrUtil.isBlank(expression)) ? null : json.getByPath(expression);
|
||||
return getByPath(json, expression, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -572,7 +572,15 @@ public class JSONUtil {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getByPath(JSON json, String expression, T defaultValue) {
|
||||
return (T) ObjectUtil.defaultIfNull(getByPath(json, expression), defaultValue);
|
||||
if((null == json || StrUtil.isBlank(expression))){
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
if(null != defaultValue){
|
||||
final Class<T> type = (Class<T>) defaultValue.getClass();
|
||||
return ObjectUtil.defaultIfNull(json.getByPath(expression, type), defaultValue);
|
||||
}
|
||||
return (T) json.getByPath(expression);
|
||||
}
|
||||
|
||||
/**
|
||||
|
27
hutool-json/src/test/java/cn/hutool/json/IssueI3BS4S.java
Normal file
27
hutool-json/src/test/java/cn/hutool/json/IssueI3BS4S.java
Normal file
@ -0,0 +1,27 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 测试带毫秒的日期转换
|
||||
*/
|
||||
public class IssueI3BS4S {
|
||||
|
||||
@Test
|
||||
public void toBeanTest(){
|
||||
String jsonStr = "{date: '2021-03-17T06:31:33.99'}";
|
||||
final Bean1 bean1 = new Bean1();
|
||||
BeanUtil.copyProperties(JSONUtil.parseObj(jsonStr), bean1);
|
||||
Assert.assertEquals("2021-03-17T06:31:33.099", bean1.getDate().toString());
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Bean1{
|
||||
private LocalDateTime date;
|
||||
}
|
||||
}
|
@ -19,4 +19,12 @@ public class JSONPathTest {
|
||||
value = JSONUtil.parseArray(json).getByPath("[1].name");
|
||||
Assert.assertEquals("mingzi", value);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getByPathTest2(){
|
||||
String str = "{'accountId':111}";
|
||||
JSON json = JSONUtil.parse(str);
|
||||
Long accountId = JSONUtil.getByPath(json, "$.accountId", 0L);
|
||||
Assert.assertEquals(111L, accountId.longValue());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user