java - jackson - MessageBodyWriter Not Found when returning a JSON POJO from a GET Api -


i trying return simple json response using jackson.

@get     @produces(mediatype.application_json)     public fmsresponseinfo test(){         system.out.println("entered function");         fmsresponseinfo fmsresponseinfo = new fmsresponseinfo();         list<searchdetailsdto> searchdetailsdtolist = new arraylist<>();         (int = 0; < 5; i++) {             searchdetailsdto searchdetailsdto = new searchdetailsdto();             searchdetailsdto.setbarcode("barcode" + i);             searchdetailsdto.setdocno("docno" + i);             searchdetailsdto.setdoctype("doctype" + i);             searchdetailsdtolist.add(searchdetailsdto);         }         fmsresponseinfo.setstatus("200");         fmsresponseinfo.setmessage("success");         fmsresponseinfo.setdata(searchdetailsdtolist);         system.out.println("exiting function");         return fmsresponseinfo;     } 

this code. when function tries return fmsresponseinfo pojo :

package com.fms.core; import com.fasterxml.jackson.annotation.jsoninclude; import com.fasterxml.jackson.annotation.jsonproperty; import com.fasterxml.jackson.annotation.jsonpropertyorder; @jsoninclude(jsoninclude.include.non_null) @jsonpropertyorder({ "status", "message", "data" }) public class fmsresponseinfo {     @jsonproperty("status")     private string status;     @jsonproperty("message")     private string message;     @jsonproperty("data")     private object data;     //getters , setters } 

this pojo sent back.

but soons function tries return , exception :

may 14, 2015 9:54:57 org.glassfish.jersey.message.internal.writerinterceptorexecutor$terminalwriterinterceptor aroundwriteto severe: messagebodywriter not found media type=application/json, type=class com.fms.core.fmsresponseinfo, generictype=class com.fms.core.fmsresponseinfo.

i have included jackson-annotation-2.4.2.jar, jackson-core-2.4.2.jar , jackson-databind-2.4.2.jar. these 3 jackson jars have included along other jars required jersey 2.16 , hibernate , mysql.

please me resolve issue !!

you need more jackson, need jackson jax-rs provider.

enter image description here

then register either in web.xml

<init-param>     <param-name>jersey.config.server.provider.packages</param-name>     <param-value>         your.resource.provider.package,         com.fasterxml.jackson.jaxrs.json     </param-value> </init-param> 

or in resourceconfig

packages("your.resource.provider.packgae",          "com.fasterxml.jackson.jaxrs.json"); 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -