VishalDevgire
VishalDevgire

Reputation: 4278

How to accept JSON pojo representation and a path param in jersey

I'm working on REST web-service where in one PUT request i have to accept two things :

  1. String id;

  2. JSON representation of POJO (Basically a POJO).

I can have a @PathParam for 'id' but what should i use for 'second' parameter (POJO)?.

How can i write my method for PUT request:

@PUT
public String doSomething(// What will go here?)
{
  // code
}

Upvotes: 1

Views: 1033

Answers (1)

user1907906
user1907906

Reputation:

@PUT
@Path("/{id}")
@Accepts("application/json")
public Response putPojo(@PathParam("id") String id, Pojo pojo) {
  return Response.ok().build();
}

If the Pojo class has JAXB annotations, JAX-RS will map the incoming JSON to a POJO instance.

@XmlRootElement
public class Pojo {
  @XmlElement
  String id;

  // Getter, Setter, ...
}

Upvotes: 2

Related Questions