我有以下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”适用于Interface,而不适用于correcht Java POJO。现在我想,我需要一个deserialzer,这是我自己写的。
答案 0 :(得分:0)
您的JSON是一个数组,而不是一个对象。