Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using @Consume with GET request in Jersey Rest

I'm trying to bind values in a GET request to a POJO.

The values are parameters in a HTTP GET request. I'm using JSONP to pass the parameters however it looks like JSONP pushes the JSON object up onto the Request line so its not really a JSON object which is being sent but instead just name value pairs on the URL.

Is it possible to map the values in my GET request to a POJO? Jersey gives the following exception when i try binding

A HTTP GET method, public void handleJSONP(MyPojo), should not consume any entity.

The binding code is looking in the request body however it doesnt exist because it is a GET request. Is there any other way to bind the values in the request without having to manually include a @QueryParam entry for each ?

Thanks

like image 726
cdugga Avatar asked Dec 10 '22 01:12

cdugga


1 Answers

I was able resolve this by using @com.sun.jersey.api.core.InjectParam of jersey

public JSONWithPadding doSomething(@InjectParam final MyPojo argPojo) 

Then the Pojo looks like this

public class MyPojo 
{
/** */
@QueryParam("value1")
private String value1;

/** */
@QueryParam("value2")
private String value2;

/** */
@QueryParam("value3")
private List<String> value3;
like image 114
cdugga Avatar answered Feb 04 '23 10:02

cdugga