简体   繁体   English

带有@GET restful 注释的 Stackoverflow 错误

[英]Stackoverflow error with @GET restful annotation

So I have tried returning multiple types of variables, including User, List and Response.所以我尝试返回多种类型的变量,包括用户、列表和响应。 All of these give me back a stackoverflow error in the get path page.所有这些都让我在获取路径页面中返回了一个 stackoverflow 错误。 I have found through the server log it is a serializing recursion, however I cannot seem to fix it, no matter how I try it.我通过服务器日志发现它是一个序列化递归,但是无论我如何尝试,我似乎都无法修复它。 Have seen multiple online tutorials/pages on stackoverflow and still I can fix it.在 stackoverflow 上看过多个在线教程/页面,但我仍然可以修复它。

I am running payara version 184 and java 8 ee, and these are project specifications, so I cant change the tecnologies.我正在运行 payara 版本 184 和 java 8 ee,这些是项目规范,所以我无法更改技术。 Intellij Idea Ultimate IDE and chrome browser/postman to check url. Intellij Idea Ultimate IDE 和 chrome 浏览器/邮递员检查 url。

public class User {
private String nome;
private int idade;
private String empresa;
private String email;
//private Boolean auth;

public User (String n , int i, String e, String em/*, Boolean a*/){
    this.nome = n;
    this.idade = i;
    this. empresa = e;
    this.email = em;
    //this.auth = a;
}

public User getUser(){
    return this;
}

interface for the restful class methods @GET @Path(ApplicationPaths.GET) @Produces(MediaType.APPLICATION_JSON) @APIResponse(responseCode = "200") User getJson( @Parameter(ref = Parameters.QUERY) @QueryParam(Parameters.QUERY) String query);宁静的 class 方法的接口 @GET @GET @Path(ApplicationPaths.GET) @Produces(MediaType.APPLICATION_JSON) @APIResponse(responseCode = "200") User getJson( @Parameter(ref = Parameters.QUERY) @QueryParam(Parameters.QUERY) String query);

Actual class implementation实际 class 实现

@ApplicationScoped 
public class KickoffApiImpl implements KickoffApi {

@Inject
private KickoffService kickoffService;

@Override
public User getJson(final String query) {
    /*
    List<User> users = new ArrayList<>();
    users.add(new User("pedro", 22, "ctw", "pelan05@gmail.com"));
    users.add(new User("paulo", 50, "ctw", "123abc@gmail.com"));
    users.add(new User("maria", 32, "ctw", "abc123@gmail.com"));

    return users.get(1);
    */

    User u = new User("maria", 32, "ctw", "abc123@gmail.com");
    return u;
    //return Response.ok(kickoffService.getUser()).build();
}

My expected output would be a Json page with the 'User' class info on the browser.我预期的 output 将是一个 Json 页面,在浏览器上显示“用户”class 信息。

PS: Server Log error: https://pastebin.com/xgRfazE9 PS:服务器日志错误: https://pastebin.com/xgRfazE9

Ok, funny enough I solved my own question by looking at my post.好的,很有趣,我通过查看我的帖子解决了我自己的问题。 So the recursion was due to the getUser method I implemented in the User class.所以递归是由于我在用户 class 中实现的 getUser 方法。 TY if you tried to read and solve this. TY 如果您尝试阅读并解决此问题。

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

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