Results 1 to 3 of 3

Thread: Multiple top level items in a JSON response?

  1. #1
    Join Date
    Mar 2007
    Posts
    128

    Question Multiple top level items in a JSON response?

    I'm trying to return a JSON object from a request which is working fine. The problem is I'm using a 3rd party javascript plugin and it's looking for something at the top level, but Spring is returning the object first. Here's an example of what I mean.

    Code:
    @RequestMapping(...)
    public MyModel getItems(...) {
        ...
        return myModel;
    }
    Here is what is returned to the browser:
    {"myModel":{"myItem1":2,"myItem2":2}}

    Is there a way to only show the sub-items as the top level instead of the main object?
    What I want is this:
    {"myItem1":2,"myItem2":2}

  2. #2
    Join Date
    Mar 2007
    Posts
    561

    Default

    The standard spring mvc setup with jackson would return what you want: {"myItem1":2,"myItem2":2}.
    Normally I would say a @ResponseBody is missing.
    How did you setup the json marshalling?

  3. #3
    Join Date
    Mar 2007
    Posts
    128

    Default

    Yep - @ResponseBody did the trick. I think without that it was putting my object in the model before passing it back to the browser.

    Thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •