Add support for @ResponseBody to return JSON #7

Closed
achuinard opened this Issue Oct 7, 2012 · 4 comments

Comments

Projects
None yet
2 participants
@achuinard

I took a bit of time trying to figure out how to properly configure JSON responses when @responsebody is used on a controller and Tiles when a String is returned by a controller. Would this be pretty simple to do?

@kolorobot

This comment has been minimized.

Show comment
Hide comment
@kolorobot

kolorobot Oct 8, 2012

Owner

JSON with @responsebody is pretty simple to setup.

Owner

kolorobot commented Oct 8, 2012

JSON with @responsebody is pretty simple to setup.

@achuinard

This comment has been minimized.

Show comment
Hide comment
@achuinard

achuinard Oct 8, 2012

I understand, but like I said I was struggling to properly configure it in
the WebMvcConfig.java. I am not sure how to get both Tiles and JSON to be
returned depending on method signature.

On Mon, Oct 8, 2012 at 9:56 AM, Rafal Borowiec notifications@github.comwrote:

JSON with @responsebody is pretty simple to setup.


Reply to this email directly or view it on GitHubhttps://github.com/kolorobot/spring-mvc-quickstart-archetype/issues/7#issuecomment-9228424.

I understand, but like I said I was struggling to properly configure it in
the WebMvcConfig.java. I am not sure how to get both Tiles and JSON to be
returned depending on method signature.

On Mon, Oct 8, 2012 at 9:56 AM, Rafal Borowiec notifications@github.comwrote:

JSON with @responsebody is pretty simple to setup.


Reply to this email directly or view it on GitHubhttps://github.com/kolorobot/spring-mvc-quickstart-archetype/issues/7#issuecomment-9228424.

@kolorobot

This comment has been minimized.

Show comment
Hide comment
@kolorobot

kolorobot Oct 8, 2012

Owner

Recently I implemented something like this (in project setup from this archetype):

    @ExceptionHandler
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public String handleInvalidJsonException(MethodArgumentNotValidException error) {
    LOG.warn("handling json input validation error with message [{}]", error.toString());
    return "0";
}

So if this works for the above, it should also work for @requestmapping annotated method

Owner

kolorobot commented Oct 8, 2012

Recently I implemented something like this (in project setup from this archetype):

    @ExceptionHandler
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public String handleInvalidJsonException(MethodArgumentNotValidException error) {
    LOG.warn("handling json input validation error with message [{}]", error.toString());
    return "0";
}

So if this works for the above, it should also work for @requestmapping annotated method

kolorobot added a commit that referenced this issue Oct 16, 2012

Issue #7: Added support for @ResponseBody to return JSON with Jackson
library; added one reference method in user controller that returns
logged in user's data as JSON
@kolorobot

This comment has been minimized.

Show comment
Hide comment
@kolorobot

kolorobot Oct 16, 2012

Owner

Hello,
I just added support for JSON in the archetype. I hope it helps you. Thanks for the tip. See changes here: 039a56d

Owner

kolorobot commented Oct 16, 2012

Hello,
I just added support for JSON in the archetype. I hope it helps you. Thanks for the tip. See changes here: 039a56d

@kolorobot kolorobot closed this Oct 16, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment