j-money
j-money

Reputation: 529

Display POJO as json

I am wondering how I can display a POJO as a json object in a REST endpoint. This is the current controller.

@RequestMapping("/Stats")
public Statistics statsPage() {
    stats = scheduler.getStats();
    return stats;
}

however it returns the error that it couldn't find the corresponding .jsp file in my WEB-INF folder. (Likely due to the fact that I don't have one). So how am I to either a.)Display the pojo as a json object in the jsp file, or the more preferred method b.)just return the pojo as a json object?

Upvotes: 0

Views: 81

Answers (1)

j-money
j-money

Reputation: 529

Nevermind, I forgot to add @ResponseBody annotation to the controller (facepalm)

@RequestMapping("/Stats")
@ResponseBody
    public Statistics statsPage() {
        stats = scheduler.getStats();
        return stats;
    }

Upvotes: 2

Related Questions