我有以下 JSON 代码:
{
"tstamp": "2012-11-21 18:00",
"id": 123,
"publicationList": [
{
"id": "1",
"state": "Publication.IMMEDIATELY",
"channel": "Channel.TIMETABLE",
"startDate": "2001-12-17",
"endDate": "2001-12-17"
}
]
}
现在我想生成一个 Java 对象。请记住,publicationList 是一个 Java.Util.List
MessageDto messageDto = gson.fromJson(FileUtils.readFileToString(new File(
"mapper/message.json")),
MessageDto.class);
Gson 配置:
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm").create();
我收到以下错误消息:
com.google.gson.JsonParseException: The JsonDeserializer com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@3782da3d failed to deserialize json object [{"id":"1","state":"Publication.IMMEDIATELY","channel":"Channel.TIMETABLE","startDate":"2001-12-17","endDate":"2001-12-17"}]
我忘记了一个重要信息!“publicationList”与接口一起使用,而不是与正确的 Java POJO 一起使用。现在我想,我需要一个我自己编写的反序列化器。