1

I am getting MessageBodyWriter not found for media type=application/json while calling rest web service.

Rest web service class :-

  @Path("/DBCall")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public class AdDAO {

    @GET
    @Path("/retrieveAds")
    @Produces("application/json")
    public Response retrieveAds(){
        DAOOTPAuthentication dao = new DAOOTPAuthentication();
        List<AdBean> AdBeans = dao.getSearchResult("Accommodation", "All Item Types", "All Sub Item Types", "Available", null);
        GenericEntity<List<AdBean>> list = new GenericEntity<List<AdBean>>(AdBeans) {};
        return Response.ok(list).build();
        }
    }

Bean Class :-

@XmlRootElement(name="adBean")
    public class AdBean implements Comparable<AdBean> {
    public AdBean() {
        super();
    }

    @XmlElement
    private String firstName;
    @XmlElement
    private String lastName;
    @XmlElement
    private String emailId;
    @XmlElement
    private String id;
    }

HTML File :-

    <script type="text/javascript">

    function valid(){
 alert("in jax");
 var json;
 $.ajax({
        type: 'GET',
        url: 'softmart/DBCall/retrieveAds',
        data: json,
        dataType: 'JSON',
        success: function (json) {
            alert('test');
            return true;
        },
        error: alert('fail')
}); 
}
    </script>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
    <script type="text/javascript" src="jquery-1.12.1.min.js"> </script>
    </head>
    <body>

    <a onclick="valid();"> sClick</a> <br/>

    <a href="softmart/DBCall/retrieveAds"> Hello</a>
    </body>

    </html>

I have included all the jars of jersey but still i am not able to run this program. I have also included jackson jar but unable to run this code. i am using eclipse for project creation and deployment.

Saurabh Oza
  • 169
  • 4
  • 18

0 Answers0