mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
修复JSONConfig.setDateFormat设置后toBean无效问题
This commit is contained in:
@@ -130,7 +130,7 @@ public class JSONConverter implements Converter<JSON> {
|
||||
|
||||
final JSONConfig config = ((JSONGetter<?>) value).getConfig();
|
||||
final Converter<T> converter = new BeanConverter<>(targetType,
|
||||
InternalJSONUtil.toCopyOptions(config).setIgnoreError(ignoreError));
|
||||
InternalJSONUtil.toCopyOptions(config).setIgnoreError(ignoreError).setFormatIfDate(config.getDateFormat()));
|
||||
return converter.convertWithCheck(value, null, ignoreError);
|
||||
}
|
||||
}
|
||||
|
22
hutool-json/src/test/java/cn/hutool/json/Issue3713Test.java
Normal file
22
hutool-json/src/test/java/cn/hutool/json/Issue3713Test.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
|
||||
public class Issue3713Test {
|
||||
@Test
|
||||
void toBeanTest() throws ParseException {
|
||||
String jsonStr = "{\"operDate\":\"Aug 22, 2024, 4:21:21 PM\"}";
|
||||
final CustomerCreateLog bean = JSONUtil.toBean(jsonStr, JSONConfig.create().setDateFormat("MMM dd, yyyy, h:mm:ss a"), CustomerCreateLog.class);
|
||||
Assertions.assertEquals("Thu Aug 22 16:21:21 CST 2024", bean.getOperDate().toString());
|
||||
}
|
||||
|
||||
@Data
|
||||
private static class CustomerCreateLog{
|
||||
private Date operDate;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user