The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

408400 (1) [Avatar] Offline
#1
The very first example in the book is slightly misleading in terms of its return value. Here is the code:

public String hello (@PathVariable("firstName") String firstName,
   @PathVariable("lastName") String lastName)
{
   return String.format("{\"message\":\"Hello %s %s\"}", firstName, lastName);
}


As a first time reader/ user, I would assume that this would return me JSON data, but that's not true as we are just returning a String (although it "looks" like JSON). More specifically, the HTTP header in the response is text/html instead of application/JSON.

I would request the example be either changed to the following OR we just return "Hello %s %s" without mentioning the "message" key part.

    public Map<String, String> hello (@PathVariable("firstName") String firstName,
                                      @PathVariable("lastName") String lastName) {
        Map<String, String> response = new HashMap<>();
        response.put("message", String.format("Hello %s %s", firstName, lastName));
        return response;
    }