简体   繁体   English

发送不为空或空的列表时,RestyGWT + Jersey错误500

[英]RestyGWT + Jersey Error 500 when sending a not null or empty List

Say I have a Jersey Resource somewhat similar to this: 假设我有一个类似于以下内容的Jersey资源:

@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: 还有一个像这样使用它的RestyGWT服务:

@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. 但是,当List为null或为空时,资源的逻辑将执行应有的工作,并且我可以对其进行调试而没有任何问题。

The contents of the JSONRepresentation don't really seem to matter for this problem. JSONRepresentation的内容似乎对这个问题并不重要。

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. 我不知道为什么会这样,而且我真的找不到任何类似的问题,我们将不胜感激。

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. 希望能有所帮助。

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) 问题是,问题实际上出在我的json表示形式中,我已经用私有变量以及每个变量的getter和setters定义了它(我上面有一些其他json表示形式的集合和实例以及其他String和基本变量)

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 事实是,由于某种原因,我真的想了解更多信息,如果将具有其他json表示形式的变量设置为私有,则会发生此错误

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). 因此,我只是将该变量设置为public,并且一切正常,奇怪的是,另一个json表示形式类的Collections甚至可以作为私有变量(primitive,String和Date也可以正常工作)正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM