0

Say I have a Jersey Resource somewhat similar to this:

@Path("/test")
public class TestResource{
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response test(List<JSONRepresentation> json){
    //some logic that gives different responses, all just Strings
    }
}

And a RestyGWT Service that consumes it like this:

@Path("api/test")
public interface TestService extends RestService{

@POST
public void test(List<JSONRepresentation> json, MethodCallback<String> callback);
}

The thing is that, when I try to access the Resource using the Service, if the List isn't null or empty I get an Internal Server Error that doesn't have anything to do with the server code because I can't even debug the test method logic.

However, when the List is null or empty, the Resource's logic does what it should and I can debug it without any problems.

The contents of the JSONRepresentation don't really seem to matter for this problem.

I have no idea why this is even happening and I couldn't really find any similar questions around, any help would be really appreciated.

Alan Dávalos
  • 2,568
  • 11
  • 19

2 Answers2

0

If you want to send Strings back to the client, change your code to:

@Path("/test")
public class TestResource{
    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public String test(List<JSONRepresentation> json){
      //some logic that gives different responses, all just Strings
    }
}

and change the code of your resource to:

@Path("api/test")
public interface TestService extends RestService{

   @POST
   public void test(List<JSONRepresentation> json, TextCallback callback);
   }
}

hope that helps.

El Hoss
  • 3,767
  • 2
  • 18
  • 24
  • Note that if you want to send back strings you probably want to change `@Produces(MediaType.APPLICATION_JSON)` to `@Produces(MediaType.TEXT_PLAIN)` ... – Ronan Quillevere Jul 24 '15 at 08:43
  • Thanks for answering. Removing the `@Consumes` annotation didn't affect the result at all, changing the `@Produces`annotation to Text Plain had the same result too, I still can't send a List with even one element in it – Alan Dávalos Jul 24 '15 at 16:11
0

Ok, I somehow figured out why the error happened and how to avoid it.

The thing is, the problem was actually in my json representation, I had defined it with private variables and getters and setters for each one of them (I have some sets and instances of other json representations on it along with other String and primitive variables)

The thing is that, for some reason I'd really want to know more about of, if a variable with a type of another json representation is set as private, this error happens

So, I just set that variable as public and everything worked fine, the odd part is that Collections of another json representation classes work fine even as private variables (primitives, String, and Date work fine like that too).

Alan Dávalos
  • 2,568
  • 11
  • 19