Dave
Dave

Reputation: 215

trying to build a Response object for a Java RESTful service

I am trying to build a Response object with a information I am getting back from a database. The information I am getting back is in a Change object:

The change.getDocument() coming back is:

{"testSolution":false,"solutionId":333,"clientId":4018593,"firewall":false,"pod":"pod3.dmy3","networkPolicy":{"speed":"1","subnets":{"nat":{"vlan":3004,"cidr":["110.168.0.0/24"]},"private":{"vlan":3004,"cidr":["15.10.1.128/25"]}}}}

So I am creating a Response like this:

 return Response.status(422).location(location).entity(changeRequest).build();

In the unit test I do this:

    String responseJson = response.readEntity(String.class);
    System.out.println("The response is: " + responseJson);

For testing, but I get this result:

The response is: {"object_id" : 333,"object_type" : "class com.entities.Solution", "operation" : "", "revision" : 0, "remote_user" : "",   "remote_host" : "", "created" : "", "published" : "", "comment" : "HTTP Status Code 422", "error" : "HTTP Status Code 422, there is a pending change request for this Solution. Replying with pending ChangeRequest",  "document" : {} }

Everything is as expected, but the document node contains no information. Am I building the Response object correctly?

Upvotes: 0

Views: 2548

Answers (1)

zoran jeremic
zoran jeremic

Reputation: 2138

Try to return it in this way:

Response.status(Status.OK).type(MediaType.APPLICATION_JSON)
                .entity(changeRequest).build();

Upvotes: 1

Related Questions