com.google.gson.JsonParseException: The JsonDeserializer com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@2d7440 failed to deserialized json object [{"id":"30102010113847691504","titulo":"CIty of Angel","descricao":"Um belo filme","date":"30/11/2010 13:38:47"},{"id":"30102010115514196289","titulo":"CIty of Angel","descricao":"Um belo filme","date":"30/11/2010 13:55:14"},{"id":"3010201011561620697","titulo":"CIty of Angel","descricao":"Um belo filme","date":"30/11/2010 13:56:01"},{"id":"3010201012829669834","titulo":"CIty of Angel","descricao":"Um belo filme","date":"30/11/2010 14:08:29"},{"id":"3010201012849669427","titulo":"CIty of Angel","descricao":"Um belo filme","date":"30/11/2010 14:08:49"},{"id":"3010201012919920893","titulo":"CIty of Angel","descricao":"Um belo filme","date":"30/11/2010 14:09:19"}] given the type java.util.List
at com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:63)
at com.google.gson.JsonDeserializationVisitor.invokeCustomDeserializer(JsonDeserializationVisitor.java:88)
at com.google.gson.JsonDeserializationVisitor.visitUsingCustomHandler(JsonDeserializationVisitor.java:76)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:106)
at com.google.gson.JsonDeserializationContextDefault.fromJsonArray(JsonDeserializationContextDefault.java:64)
at com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:49)
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 classes.Manip.receberMetaDados(Manip.java:64)
at servlet.OurTube_Servlet.buscar(OurTube_Servlet.java:105)
at servlet.OurTube_Servlet.doPost(OurTube_Servlet.java:55)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.RuntimeException: No-args constructor for class classes.Video does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
at com.google.gson.MappedObjectConstructor.constructWithNoArgConstructor(MappedObjectConstructor.java:64)
at com.google.gson.MappedObjectConstructor.construct(MappedObjectConstructor.java:53)
at com.google.gson.JsonObjectDeserializationVisitor.constructTarget(JsonObjectDeserializationVisitor.java:40)
at com.google.gson.JsonDeserializationVisitor.getTarget(JsonDeserializationVisitor.java:56)
at com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:109)
at com.google.gson.JsonDeserializationContextDefault.fromJsonObject(JsonDeserializationContextDefault.java:73)
at com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:51)
at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.deserialize(DefaultTypeAdapters.java:548)
at com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.deserialize(DefaultTypeAdapters.java:510)
at com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:50)
... 25 more

1 Answer
1

That depends. If it is to be returned as a HTTP response on a HTTP request, then you need to convert it to a string following a specific format. The popular ones are XML and JSON. The other end has just to read the XML or JSON string in and then recreate the list based on this information.

Here's an example with JSON and Google Gson which is able to convert Java objects to JSON and vice versa.

Hi,i do what you say, is working, but in my calling servlet i having this error : "The JsonDeserializer com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@1b11b79 failed to deserialized json object" This is my code in my calling servlet: List<Video> results = new Gson().fromJson(json, new TypeToken<List<Video>>(){}.getType()); Any idea ?
–
Valter HenriqueNov 30 '10 at 16:33

Isn't there more into the trace which tells about the root cause? Anyway, ensure that Video class is exactly the same on both sides.
–
BalusCNov 30 '10 at 16:34