I have a REST service operation defined in a controller class, as shown:
@POST
@Consumes({MediaType.APPLICATION_JSON})
@Path("create")
public Response createWidget(@BeanParam Widget widget) {
...
}
Widget is a POJO bean class, i.e. 2 private fields named foo
& bar
of type String
with public getters & setters, and a public no-arg constructor.
The POST request body is:
{ "foo": "Some text", "bar": "Some more text" }
and has header Content-Type: application/json
On firing this request, the createWidget
method gets a Widget
object as argument but both String
fields are null
.
Can someone tell me what else is needed for the fields to be populated? I think some annotations may be required in the POJO bean class. If the content type was application/x-www-form-urlencoded
, then I know that the fields should be annotated @FormParam
, but I'm not sure what the annotation should be for application/json
content.
Thanks a lot for your help... - Ajoy