I am running an google places api the response i received is in json format i have also checked it in json viewer,
{
"html_attributions" : [],
"next_page_token" : "CvQB7AAAAKcVCYUk92u8YbCxucwIYZZoVsNOAX1utAinxpRnjirhCWRGYI1ozjaw-9JauOVcr8iOqsvGVR3n183oJ-saMliylmFcPdJ8HwhIpxwWr8EsXDuTk4SCIYfSfcpSflBaWMqorPnNHAVMz9HS3r4q8Hq-UUobHHfD8HZ4auX9eOzVHETQezM0eT8164h1qsRChdvzEQdsxu1nze6c3GI6xO_PByuSeI8tksFlrPm2P45cZda-_qpQlmn_ksZiCzTRnpPGYG0U7AgtpoiUK85WTAX5CkH7jFpjYFap6LSSv33ujQtFFk52CECLu_iudN78IhIQri7z9TjtM4StCVCRS0Do6RoUrMm6kpd4rUbKD7LkTqbq3o7DOZU",
"results" : [
{
"geometry" : {
"location" : {
"lat" : -33.8599827,
"lng" : 151.2021282
},
"viewport" : {
"northeast" : {
"lat" : -33.8552624,
"lng" : 151.2031401
},
"southwest" : {
"lat" : -33.8657895,
"lng" : 151.2000123
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "92f1bbd4ecab8e9add032bccee40a57a8dfd42b4",
"name" : "Barangaroo",
"place_id" : "ChIJ1ZL9NkGuEmsRUEkzFmh9AQU",
"reference" : "CpQBhQAAAE4kOaitGfNEGHyhPnHMiP5NVmC9UsUYoYyOtBcO7zKBMNHR07V90Ohq6AV8qEWIAy0xpMvzlEimcdzW0KwdtCbUpWYKXFhby57oPCCUbMiIy_9yxPhtmnzcWFOMZqWWUnVxpYOW6hHR_JbLUbFRPZCSYqMJ9VL6xpxAbjulKVJFmJP4enq7MyeMe8rO0lJRCRIQelNwAky9wPZz9iyjcT7-UhoUGMbpbFWZZeZDjpOxJyipeWTTRxk",
"scope" : "GOOGLE",
"types" : [ "locality", "political" ],
"vicinity" : "Barangaroo"
}]
}
I have used in this way the models 1.GooglePlacesModel is main model which contains List results; and 2.PlacesMainModel contains List geometry; again submodels i used as per need Now i m able to receive string fields in results array like name,icon but m failing to receice the geometry fields like location I came across the following stack trace
GooglePlacesModel plcModel = gson.fromJson(resultedPLaces, GooglePlacesModel.class);
where resultedPLaces is the json string as it is above,
googleapis.com:443][total kept alive: 1; route allocated: 1 of 2; total allocated: 1 of 20]
com.google.gson.JsonParseException: The JsonDeserializer com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@356dd6e9 failed to deserialized json object {"geometry":{"location":{"lat":-33.8599827,"lng":151.2021282}}} given the type com.google.gson.ParameterizedTypeImpl@53b59b06
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.JsonDeserializationContextDefault.fromJsonObject(JsonDeserializationContextDefault.java:73)
at com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:51)
at com.google.gson.Gson.fromJson(Gson.java:568)
at com.google.gson.Gson.fromJson(Gson.java:515)
at com.google.gson.Gson.fromJson(Gson.java:484)
at com.google.gson.Gson.fromJson(Gson.java:434)
at com.google.gson.Gson.fromJson(Gson.java:406)
at com.webapp.actions.api.places.NearByPlacesAction.getNrByPlaces(NearByPlacesAction.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:140)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:158)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:101)
2.PlacesMainModel contains List geometry;
Geometry is not JSONArray so you can't take it as list its a simple nested json object.
Make another model for Geometry and use it i place of List Geometry.