Jackson does not serialize Jsonobject object

Asked

Viewed 133 times

2

I have a service like this:

@Path("/test")
public class TestEndPoint {

    @GET
    @Produces("application/json")
    public Response get(){
        POJO pojo = new POJO();
        pojo.setName("Rafael");

        return Response.ok(pojo).build();
    }

}

and works perfectly

but with Jsonobject, it doesn’t work

@Path("/test")
public class TestEndPoint {

    @GET
    @Produces("application/json")
    public Response get(){
        org.json.JSONObject json = new org.json.JSONObject();
        json.put("name", "Rafael");

        return Response.ok(json).build();
    }

}

I use the Jbossas 7.1 with Jackson Provider.

ps - I have a web service with JERSEY and it works perfectly with Jsonobject, but not with RESTEASY. I need to do it. toString so he can generate the answer without exception.

  • Can you translate your question? Here is the OS in English.

  • 1

    Putz, I swear I was asking in . com, I will correct

  • By the way, the negative vote was not me, so much that I commented here to warn you.

  • No problem, it’s part of it. It was my fault.

  • What exception does it give? You will probably need a preview for this type of object.

1 answer

2

Hello,

Build using the Jsonobjectbuilder:

@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("getnamejson")
public Response getnamejson() {
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    jsonObjectBuilder.add("name", "Rafael");

    return Response.ok(jsonObjectBuilder.build()).build();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.