改进TemporalAccessorSerializer支持dayOfMonth和month枚举名

This commit is contained in:
Looly
2023-09-21 13:06:16 +08:00
parent 01cb9bdd26
commit 6d33c3f413
4 changed files with 119 additions and 5 deletions

View File

@@ -0,0 +1,43 @@
package cn.hutool.json;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.lang.TypeReference;
import lombok.Data;
import org.junit.Assert;
import org.junit.Test;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
public class IssueI82AM8Test {
@Test
public void toBeanTest() {
final String json = ResourceUtil.readUtf8Str("issueI82AM8.json");
Map<String, MedicalCenter.MedicalCenterLocalized> bean1 =
JSONUtil.toBean(json, new TypeReference<Map<String, MedicalCenter.MedicalCenterLocalized>>() {
}, false);
bean1.forEach((k, v) -> Assert.assertNotNull(v.getTestimonials()));
}
// 对象
@Data
public static class MedicalCenter {
private Map<String, MedicalCenterLocalized> medicalCenterLocalized;
@Data
public static class MedicalCenterLocalized {
private List<Testimonial> testimonials;
@Data
public static class Testimonial {
private LocalDateTime createTime;
}
}
}
}

View File

@@ -0,0 +1,46 @@
{
"en": {
"testimonials": [
{
"createTime": {
"dayOfYear": 261,
"dayOfWeek": "MONDAY",
"year": 2023,
"month": "SEPTEMBER",
"nano": 0,
"monthValue": 9,
"dayOfMonth": 18,
"hour": 15,
"minute": 18,
"second": 0,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
}
}
]
},
"zh": {
"testimonials": [
{
"createTime": {
"dayOfYear": 261,
"dayOfWeek": "MONDAY",
"year": 2023,
"month": "SEPTEMBER",
"nano": 0,
"monthValue": 9,
"dayOfMonth": 18,
"hour": 15,
"minute": 18,
"second": 0,
"chronology": {
"id": "ISO",
"calendarType": "iso8601"
}
}
}
]
}
}