发送非空或空列表时 RestyGWT + Jersey 错误 500
RestyGWT + Jersey Error 500 when sending a not null or empty List
假设我有一个 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
}
}
还有一个像这样使用它的 RestyGWT 服务:
@Path("api/test")
public interface TestService extends RestService{
@POST
public void test(List<JSONRepresentation> json, MethodCallback<String> callback);
}
问题是,当我尝试使用服务访问资源时,如果列表不为空或为空,我会收到一个与服务器代码无关的内部服务器错误,因为我甚至无法调试测试方法逻辑。
但是,当 List 为 null 或空时,Resource 的逻辑会执行它应该执行的操作,我可以毫无问题地对其进行调试。
JSONRepresentation 的内容对于这个问题似乎并不重要。
我不知道为什么会发生这种情况,我也找不到任何类似的问题,非常感谢任何帮助。
如果要将字符串发送回客户端,请将代码更改为:
@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
}
}
并将您的资源代码更改为:
@Path("api/test")
public interface TestService extends RestService{
@POST
public void test(List<JSONRepresentation> json, TextCallback callback);
}
}
希望对您有所帮助。
好的,我以某种方式弄清楚了错误发生的原因以及如何避免它。
问题是,问题实际上出在我的 json 表示中,我已经用私有变量以及它们中的每一个的 getter 和 setter 定义了它(我有一些集合和其他 json 以及其他字符串和原始变量)
问题是,出于某种原因,我真的很想知道更多,如果将具有另一种 json 表示类型的变量设置为私有,则会发生此错误
所以,我只是将该变量设置为 public 并且一切正常,奇怪的是另一个 json 表示的集合 类 即使作为私有变量(基元)也能正常工作、字符串和日期也可以正常工作。
假设我有一个 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
}
}
还有一个像这样使用它的 RestyGWT 服务:
@Path("api/test")
public interface TestService extends RestService{
@POST
public void test(List<JSONRepresentation> json, MethodCallback<String> callback);
}
问题是,当我尝试使用服务访问资源时,如果列表不为空或为空,我会收到一个与服务器代码无关的内部服务器错误,因为我甚至无法调试测试方法逻辑。
但是,当 List 为 null 或空时,Resource 的逻辑会执行它应该执行的操作,我可以毫无问题地对其进行调试。
JSONRepresentation 的内容对于这个问题似乎并不重要。
我不知道为什么会发生这种情况,我也找不到任何类似的问题,非常感谢任何帮助。
如果要将字符串发送回客户端,请将代码更改为:
@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
}
}
并将您的资源代码更改为:
@Path("api/test")
public interface TestService extends RestService{
@POST
public void test(List<JSONRepresentation> json, TextCallback callback);
}
}
希望对您有所帮助。
好的,我以某种方式弄清楚了错误发生的原因以及如何避免它。
问题是,问题实际上出在我的 json 表示中,我已经用私有变量以及它们中的每一个的 getter 和 setter 定义了它(我有一些集合和其他 json 以及其他字符串和原始变量)
问题是,出于某种原因,我真的很想知道更多,如果将具有另一种 json 表示类型的变量设置为私有,则会发生此错误
所以,我只是将该变量设置为 public 并且一切正常,奇怪的是另一个 json 表示的集合 类 即使作为私有变量(基元)也能正常工作、字符串和日期也可以正常工作。