1
我一直在使用Jersey進行REST API並返回JSON。在客戶端,我使用google-gson。在反序列化JSON的同時,我遇到了以下錯誤。問題:使用Jersey進行序列化,使用gson反序列化JSON
com.google.gson.JsonParseException: The JsonDeserializer MapTypeAdapter failed to deserialized json object {} given the type interface java.util.Map
at com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:63)
at com.google.gson.JsonDeserializationVisitor.invokeCustomDeserializer(JsonDeserializationVisitor.java:88)
at com.google.gson.JsonObjectDeserializationVisitor.visitFieldUsingCustomHandler(JsonObjectDeserializationVisitor.java:116)
at com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:158)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:131)
at com.google.gson.JsonDeserializationCo
正在由新澤西序列化到JSON由具有物體非通用的(沒有類型指定)地圖和列表
public class Dealer implements Serializable
{
private String serviceURL;
private Map hoursService;
List dealerAttributes;
}
在這裏是由新澤西州
{"serviceURL":www.google.com,"hoursService":{"3":{"dayOfWeek":3,"closeTime":"6:30 PM","openTime":"7:30 AM"},"2":{"dayOfWeek":2,"closeTime":"6:30 PM","openTime":"7:30 AM"},"1":{"dayOfWeek":1,"closeTime":"6:30 PM","openTime":"7:30 AM"}},"dealerAttributes":[{"language":"English","dealerAttributeName":"Spanish Speaking","updateDate":1174971061000},{"language":"English","updateDate":1103003316000}]}
產生的JSON
可能是什麼原因。請幫我解決這個問題。有沒有比gson更好的其他工具?請建議。
謝謝。
同類問題:http://stackoverflow.com/questions/5424263/json-decode-custom-class-with-hashmap-member-using-gson-in-java – MatrixFrog 2011-05-14 18:52:52