java - Restful Web Service Error -
i use javax restfull web service. can return string mobile app. cant return model class. want return employee model. give error;
full error:
severe: servlet.service() servlet [jersey rest service] in context path [/cafesiparis] threw exception [servlet execution threw exception] root cause java.lang.abstractmethoderror @ org.codehaus.jackson.map.annotationintrospector$pair.findserializer(annotationintrospector.java:1148) @ org.codehaus.jackson.map.ser.basicserializerfactory.findserializerfromannotation(basicserializerfactory.java:362) @ org.codehaus.jackson.map.ser.beanserializerfactory.createserializer(beanserializerfactory.java:252) @ org.codehaus.jackson.map.ser.stdserializerprovider._createuntypedserializer(stdserializerprovider.java:782) @ org.codehaus.jackson.map.ser.stdserializerprovider._createandcacheuntypedserializer(stdserializerprovider.java:735) @ org.codehaus.jackson.map.ser.stdserializerprovider.findvalueserializer(stdserializerprovider.java:344) @ org.codehaus.jackson.map.ser.stdserializerprovider.findtypedvalueserializer(stdserializerprovider.java:420) @ org.codehaus.jackson.map.ser.stdserializerprovider._serializevalue(stdserializerprovider.java:601) @ org.codehaus.jackson.map.ser.stdserializerprovider.serializevalue(stdserializerprovider.java:256) @ org.codehaus.jackson.map.objectmapper.writevalue(objectmapper.java:1604) @ org.codehaus.jackson.jaxrs.jacksonjsonprovider.writeto(jacksonjsonprovider.java:527) @ com.sun.jersey.json.impl.provider.entity.jacksonproviderproxy.writeto(jacksonproviderproxy.java:160) @ com.sun.jersey.spi.container.containerresponse.write(containerresponse.java:306) @ com.sun.jersey.server.impl.application.webapplicationimpl._handlerequest(webapplicationimpl.java:1437) @ com.sun.jersey.server.impl.application.webapplicationimpl.handlerequest(webapplicationimpl.java:1349) @ com.sun.jersey.server.impl.application.webapplicationimpl.handlerequest(webapplicationimpl.java:1339) @ com.sun.jersey.spi.container.servlet.webcomponent.service(webcomponent.java:416) @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:537) @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:699) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ controls.simplecorsfilter.dofilter(simplecorsfilter.java:31) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:122) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:501) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:171) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:950) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:408) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1070) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:611) @ org.apache.tomcat.util.net.aprendpoint$socketprocessor.dorun(aprendpoint.java:2440) @ org.apache.tomcat.util.net.aprendpoint$socketprocessor.run(aprendpoint.java:2429) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745)
my class:
employee model:
package model; /** * * @author cengizhan */ public class employee { private string name; private string surname; private int id; public employee(int id, string name, string surname){ this.id = id; this.name=name; this.surname =surname; } /** * @return name */ public string getname() { return name; } /** * @param name name set */ public void setname(string name) { this.name = name; } /** * @return surname */ public string getsurname() { return surname; } /** * @param surname surname set */ public void setsurname(string surname) { this.surname = surname; } /** * @return id */ public int getid() { return id; } /** * @param id id set */ public void setid(int id) { this.id = id; } }
web service class:
package ws; import helper.urunhelper; import java.io.ioexception; import java.io.serializable; import java.io.stringwriter; import java.util.arraylist; import java.util.list; import java.util.logging.level; import java.util.logging.logger; import javax.ws.rs.get; import javax.ws.rs.path; import javax.ws.rs.produces; import javax.ws.rs.core.mediatype; import model.employee; import org.json.simple.jsonarray; import org.json.simple.jsonobject; import org.json.simple.jsonvalue; import org.json.simple.parser.jsonparser; import org.json.simple.parser.parseexception; @path("/wslogin") public class wslogin implements serializable { @get @produces(mediatype.application_json) @path("/returnmodel") public employee returnmodel() { employee emp = new employee(1, "jack", "jason"); return emp; } }
simplecorsfilter:
package controls; import java.io.ioexception; import javax.servlet.filter; import javax.servlet.filterchain; import javax.servlet.filterconfig; import javax.servlet.servletexception; import javax.servlet.servletrequest; import javax.servlet.servletresponse; import javax.servlet.http.httpservletresponse; /** * * @author cengizhan */ public class simplecorsfilter implements filter { @override public void dofilter(servletrequest req, servletresponse res, filterchain chain) throws ioexception, servletexception { httpservletresponse response = (httpservletresponse) res; response.setheader("access-control-allow-origin", "*"); response.setheader("access-control-allow-methods", "post, get, options, delete"); response.setheader("access-control-max-age", "3600"); response.setheader("access-control-allow-headers", "content-type"); chain.dofilter(req, res); } public void init(filterconfig filterconfig) { } public void destroy() { } }
web.xml:
<!-- web service --> <servlet> <servlet-name>jersey rest service</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.servletcontainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>ws</param-value> </init-param> <init-param> <param-name>com.sun.jersey.api.json.pojomappingfeature</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jersey rest service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> <!-- /web service -->
thank :)
looks mixing dependency versions.. try using jersey-server-1.8 , jersey-json-1.8 (and adjust dependencies versions)
maven out on this..
edit: try using following jars
Comments
Post a Comment