user5157427
user5157427

Reputation: 253

POST method that accept few arguments

Is it possible to write a @POST method that accept few arguments , some objects some primitive ? like this :

@POST
    @Consumes({MediaType.APPLICATION_JSON})
    @Produces({MediaType.TEXT_PLAIN})
    @Path("/post")
    public String postMessage(Message msg,Car car,String s,int i) throws Exception{
}

if yes - how will the request body looks like ?

Thank you

Upvotes: 0

Views: 50

Answers (1)

wonderbell
wonderbell

Reputation: 1126

It is possible by creating a wrapper container class for input. e.g.

class PostInput{
  private Message message,
  private Car car;
  private String s;
  private int i;

  // getters and setters for properties
}

then the signature of method will be

public String postMessage(PostInput input)

You'd need to form the corresponding json object in the client

Upvotes: 2

Related Questions