MessageBodyWriter not found for media type=application/json

后端 未结 10 1637
庸人自扰
庸人自扰 2020-11-30 02:13

I am facing issues while consuming JAX-RS services as JSON.

Below I have added my code.

This is my service class:

//Sets the path to base URL         


        
10条回答
  •  悲&欢浪女
    2020-11-30 02:43

    I think may be you should try to convert the data to json format. It can be done by using gson lib. Try something like below.

    I don't know it is a best solutions or not but you could do it this way.It worked for me

    example : `

    @GET
    @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
    public Response info(@HeaderParam("Accept") String accept) {
        Info information = new Info();
        information.setInfo("Calc Application Info");
        System.out.println(accept);
        if (!accept.equals(MediaType.APPLICATION_JSON)) {
            return Response.status(Status.ACCEPTED).entity(information).build();
        } else {
            Gson jsonConverter = new GsonBuilder().create();
            return Response.status(Status.ACCEPTED).entity(jsonConverter.toJson(information)).build();
        }
    }
    

提交回复
热议问题