I’m getting an exception while parsing a JSON with Gson.
The following is the exception :
com.google.gson.JsonParseException: The JsonDeserializer StringTypeAdapter failed to deserialize json object {"CGLIB$BOUND":true,"CGLIB$CONSTRUCTED":true,"CGLIB$CALLBACK_0":{"interfaces":[{}],"constructed":true,"persistentClass":{},"getIdentifierMethod":{"clazz":{},"slot":0,"name":"getmId","returnType":{},"parameterTypes":[],"exceptionTypes":[],"modifiers":1,"annotations":[0,3,0,67,0,0,0,68,0,0,0,69,0,1,0,70,115,0,71],"root":{"clazz":{},"slot":0,"name":"getmId","returnType":{},"parameterTypes":[],"exceptionTypes":[],"modifiers":1,"annotations":[0,3,0,67,0,0,0,68,0,0,0,69,0,1,0,70,115,0,71],"override":false},"override":false},"setIdentifierMethod":{"clazz":{},"slot":1,"name":"setmId","returnType":{},"parameterTypes":[{}],"exceptionTypes":[],"modifiers":1,"root":{"clazz":{},"slot":1,"name":"setmId","returnType":{},"parameterTypes":[{}],"exceptionTypes":[],"modifiers":1,"override":false},"override":false},"overridesEquals":false,"initialized":false,"entityName":"com.domain.Hotel","id":1,"unwrap":false},"mId":0,"mHotelLatitude":0.0,"mHotelLongitude":0.0,"mHotelRating":0.0,"mHotelAvgPrice":0.0} given the type class java.lang.String
JSON:
{
"CGLIB$BOUND": true,
"CGLIB$CONSTRUCTED": true,
"CGLIB$CALLBACK_0": {
"interfaces": [
{}
],
"constructed": true,
"persistentClass": {},
"getIdentifierMethod": {
"clazz": {},
"slot": 0,
"name": "getmId",
"returnType": {},
"parameterTypes": [],
"exceptionTypes": [],
"modifiers": 1,
"annotations": [
0,
3,
0,
67,
0,
0,
0,
68,
0,
0,
0,
69,
0,
1,
0,
70,
115,
0,
71
],
"root": {
"clazz": {},
"slot": 0,
"name": "getmId",
"returnType": {},
"parameterTypes": [],
"exceptionTypes": [],
"modifiers": 1,
"annotations": [
0,
3,
0,
67,
0,
0,
0,
68,
0,
0,
0,
69,
0,
1,
0,
70,
115,
0,
71
],
"override": false
},
"override": false
},
"setIdentifierMethod": {
"clazz": {},
"slot": 1,
"name": "setmId",
"returnType": {},
"parameterTypes": [
{}
],
"exceptionTypes": [],
"modifiers": 1,
"root": {
"clazz": {},
"slot": 1,
"name": "setmId",
"returnType": {},
"parameterTypes": [
{}
],
"exceptionTypes": [],
"modifiers": 1,
"override": false
},
"override": false
},
"overridesEquals": false,
"initialized": false,
"entityName": "com.domain.Hotel",
"id": 1,
"unwrap": false
},
"mId": 0,
"mHotelLatitude": 0,
"mHotelLongitude": 0,
"mHotelRating": 0,
"mHotelAvgPrice": 0
}
Does anybody have an idea about why this exception would come?
Regards
I can get this JSON to parse in Gson. The error above is generated when you have incorrectly mapped a JSON property type to Java member type in your POJO (an array type in JSON is declared as a String type in your POJO for example).
The error is a little curious to me as Gson will usually print out the JSON from the property that couldn’t be mapped. In your case that would be
CGLIB$BOUNDwhich is aboolean, but Gson behaves nicely in this case, giving you aStringvalue"true". We can more accurately identify your problem if you provide the POJO you are trying to deserialise to.