sgoldberg
sgoldberg

Reputation: 487

Null pojo with @BeanParam

I am trying to use @BeanParam with RESTEasy so that I can use swagger docs.

I have annotated my POJOs with @QueryParam.

I have gotten it to work successfully with a POST method, but am having major issues with GET

The object passed in is null no matter what I try.

Here is my pojo

  public class TestObject {
        @QueryParam("test1")
        private String test1;



        public TestObject(){

        }

        public TestObject(String test1){
            this.test1 = test1;

        }

        public String getTest1() {
            return test1;
        }

        public void setTest1(String test1) {
            this.test1 = test1;
        }


    }

and here are my methods

    // post works fine and object is there ....
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/test")
    public Response post(@BeanParam TestObject test){

        return  PhizzleResponse.response(Response.Status.OK, test, null);
    }

    @GET
    @Path("/test/")
    public Response fetch(@BeanParam TestObject activity){




        return PhizzleResponse.response(Response.Status.OK, activity, null);
    }

and here is how I am calling the method

curl "http://localhost:8080/api/test?token=somevalue&test1=12345

again POST is fine and object is populated... with GET object is null entirely.

Upvotes: 2

Views: 1084

Answers (1)

Albert Bos
Albert Bos

Reputation: 2062

I think you need to replace:

@GET
@Path("/test/")

With:

@GET
@Path("/test")

Since you are calling the URL without the / at the end.

Upvotes: 1

Related Questions