Problem description:
.UnsupportedOperationException: null
Problem analysis:
1. UseGsonSerialize, but usefastjsonDeserialization is performed, because fastjson does not support Gson serializing the json data after LocalDate and LocalDateTime types, an error is reported.
-
List<TestModel> testModelList = new ArrayList<>();
-
TestModel testModel = new TestModel();
-
(());
-
(());
-
(testModel);
-
Gson gson = new Gson();
-
String jsonStr = (testModelList);
-
testModelList = (jsonStr, );
[{"localDate":{"year":2022,"month":5,"day":18},"localDateTime":{"date":{"year":2022,"month":5,"day":18},"time":{"hour":10,"minute":27,"second":34,"nano":979527900}}}]
Solution:
1. Deserialization using Gson.
-
List<TestModel> testModelList = new ArrayList<>();
-
TestModel testModel = new TestModel();
-
(());
-
(());
-
(testModel);
-
Gson gson = new Gson();
-
String jsonStr = (testModelList);
-
testModelList = (jsonStr, new TypeToken<List<TestModel>>() {
-
}.getType());
2. The serialization and deserialization methods remain unchanged. LocalDate and LocalDateTime types are converted toStringtype.
-
List<TestModel> testModelList = new ArrayList<>();
-
TestModel testModel = new TestModel();
-
(().format(("yyyy-MM-dd")));
-
(().format(("yyyy-MM-dd HH:mm:ss")));
-
(testModel);
-
Gson gson = new Gson();
-
String jsonStr = (testModelList);
-
testModelList = (jsonStr, );