Announcement Announcement Module
Collapse
No announcement yet.
Multiple top level items in a JSON response? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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?

    Comment


    • #3
      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.

      Comment

      Working...
      X