rest - A message body writer for Java class java.util.ArrayList, and Java type class java.util.ArrayList, and MIME media type application/json was not found -


i new using jersy implementing rest api

i below error, when call products service.

 com.sun.jersey.api.messageexception: message body writer java class java.util.arraylist, , java type class java.util.arraylist, , mime media type application/json not found. 

here code:

@get @path("/products") @produces(mediatype.application_json) public response productsearch(@queryparam("name") string name) {    list<product> products = new arraylist<>();    products.add(new product("prdname", "prdcost", "prdmodel"));    return response.ok( products).build(); } 

i tried this:

@get @path("/products") @produces(mediatype.application_json) public list<product> productsearch(@queryparam("name") string name) {    list<product> products = new arraylist<>();    products.add(new product("prdname", "prdcost", "prdmodel"));    return products; } 

the below setup of environment:

  • tomcat 8,
  • jersey libraries: jersey-bundle-1.19.1,
  • not using maven

web.xml:

    <servlet>         <servlet-name>jersey-serlvet</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>org.test.rest</param-value>         </init-param>         <load-on-startup>1</load-on-startup>     </servlet>      <servlet-mapping>         <servlet-name>jersey-serlvet</servlet-name>         <url-pattern>/rest/*</url-pattern>     </servlet-mapping> 

i tried using below init-param also:

    <init-param>         <param-name>com.sun.jersey.api.json.pojomappingfeature</param-name>         <param-value>true</param-value>       </init-param> 

i tried returning genericentity, had same issue.

return response.ok().entity(new genericentity<list<product>>(products) {}).build(); 

i tried using

  • jersey-core-1.8.jar
  • jersey-json-1.8.jar
  • jersey-server-1.8.jar

instead of jersey-bundle-1.19.1

i don't have issues when return string. understand, missing json media type dependency, not figure out.

this error happens on tomcat server while client doesn't receive response obviously.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)