简体   繁体   中英

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. 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.

I am running payara version 184 and java 8 ee, and these are project specifications, so I cant change the tecnologies. Intellij Idea Ultimate IDE and chrome browser/postman to check 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);

Actual class implementation

@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.

PS: Server Log error: 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. TY if you tried to read and solve this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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