java - getting ClassCastException when iterating parameter ArrayList received from put -
using restlet, trying receive list of class foo through put method
class foo { public string name; public int age; } public class bar extends serverresource { @put public string update(arraylist<foo> foos) { string names = ""; try { (foo foo : foos ) { names += ","+foo.name; } } catch (exception e) { e.printstacktrace(); } return names; } }
however when sending json
[ { "name":"bar", "age":1 }, { "age":27, "name":"baz" } ]
i getting exception @ loop first line
java.lang.classcastexception: java.util.linkedhashmap cannot cast foo @ bar.update(bar.java:55) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.restlet.resource.serverresource.dohandle(serverresource.java:503) @ org.restlet.resource.serverresource.put(serverresource.java:1275) @ org.restlet.resource.serverresource.dohandle(serverresource.java:583) @ org.restlet.resource.serverresource.donegotiatedhandle(serverresource.java:649) @ org.restlet.resource.serverresource.doconditionalhandle(serverresource.java:348) @ org.restlet.resource.serverresource.handle(serverresource.java:952) @ org.restlet.resource.finder.handle(finder.java:246) @ org.restlet.routing.filter.dohandle(filter.java:159) @ org.restlet.routing.filter.handle(filter.java:206) @ org.restlet.routing.router.dohandle(router.java:431) @ org.restlet.routing.router.handle(router.java:648) @ org.restlet.routing.filter.dohandle(filter.java:159) @ org.restlet.routing.filter.handle(filter.java:206) @ org.restlet.routing.filter.dohandle(filter.java:159) @ org.restlet.routing.filter.handle(filter.java:206) @ org.restlet.routing.filter.dohandle(filter.java:159) @ org.restlet.engine.application.statusfilter.dohandle(statusfilter.java:155) @ org.restlet.routing.filter.handle(filter.java:206) @ org.restlet.routing.filter.dohandle(filter.java:159) @ org.restlet.routing.filter.handle(filter.java:206) @ org.restlet.engine.compositehelper.handle(compositehelper.java:211) @ org.restlet.engine.application.applicationhelper.handle(applicationhelper.java:84) @ org.restlet.application.handle(application.java:381) @ org.restlet.routing.filter.dohandle(filter.java:159) @ org.restlet.routing.filter.handle(filter.java:206) @ org.restlet.routing.router.dohandle(router.java:431) @ org.restlet.routing.router.handle(router.java:648) @ org.restlet.routing.filter.dohandle(filter.java:159) @ org.restlet.routing.filter.handle(filter.java:206) @ org.restlet.routing.router.dohandle(router.java:431) @ org.restlet.routing.router.handle(router.java:648) @ org.restlet.routing.filter.dohandle(filter.java:159) @ org.restlet.routing.filter.handle(filter.java:206) @ org.restlet.engine.compositehelper.handle(compositehelper.java:211) @ org.restlet.component.handle(component.java:392) @ org.restlet.server.handle(server.java:516) @ org.restlet.engine.serverhelper.handle(serverhelper.java:72) @ org.restlet.engine.adapter.httpserverhelper.handle(httpserverhelper.java:152) @ org.restlet.ext.servlet.serverservlet.service(serverservlet.java:1089) @ javax.servlet.http.httpservlet.service(httpservlet.java:848) @ org.eclipse.jetty.servlet.servletholder.handle(servletholder.java:684) @ org.eclipse.jetty.servlet.servlethandler.dohandle(servlethandler.java:501) @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:137) @ org.eclipse.jetty.security.securityhandler.handle(securityhandler.java:557) @ org.eclipse.jetty.server.session.sessionhandler.dohandle(sessionhandler.java:231) @ org.eclipse.jetty.server.handler.contexthandler.dohandle(contexthandler.java:1086) @ org.eclipse.jetty.servlet.servlethandler.doscope(servlethandler.java:428) @ org.eclipse.jetty.server.session.sessionhandler.doscope(sessionhandler.java:193) @ org.eclipse.jetty.server.handler.contexthandler.doscope(contexthandler.java:1020) @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:135) @ org.eclipse.jetty.server.handler.contexthandlercollection.handle(contexthandlercollection.java:255) @ org.eclipse.jetty.server.handler.handlercollection.handle(handlercollection.java:154) @ org.eclipse.jetty.server.handler.handlerwrapper.handle(handlerwrapper.java:116) @ org.eclipse.jetty.server.server.handle(server.java:370) @ org.eclipse.jetty.server.abstracthttpconnection.handlerequest(abstracthttpconnection.java:494) @ org.eclipse.jetty.server.abstracthttpconnection.content(abstracthttpconnection.java:982) @ org.eclipse.jetty.server.abstracthttpconnection$requesthandler.content(abstracthttpconnection.java:1043) @ org.eclipse.jetty.http.httpparser.parsenext(httpparser.java:865) @ org.eclipse.jetty.http.httpparser.parseavailable(httpparser.java:240) @ org.eclipse.jetty.server.asynchttpconnection.handle(asynchttpconnection.java:82) @ org.eclipse.jetty.io.nio.selectchannelendpoint.handle(selectchannelendpoint.java:667) @ org.eclipse.jetty.io.nio.selectchannelendpoint$1.run(selectchannelendpoint.java:52) @ org.eclipse.jetty.util.thread.queuedthreadpool.runjob(queuedthreadpool.java:608) @ org.eclipse.jetty.util.thread.queuedthreadpool$3.run(queuedthreadpool.java:543) @ java.lang.thread.run(thread.java:744)
any idea how can iterate through list , getting foo item attributes ?
annotate foo
@xmlrootelement
. otherwise json serializer not know class want unserialize.
Comments
Post a Comment