Reputation: 406
I have simple resource which should return JSON array, but it returns object in which is array:
@RequestMapping(value = "/types", method = RequestMethod.GET)
public List <JsonObject> types() {
ArrayList <JsonObject> list=new ArrayList<JsonObject>();
list.add(new JsonObject("Audi"));
list.add(new JsonObject("Mercedes"));
return list;
}
Where JsonObject is simple class with three String atributes (value,id,label).
Returns:
{"jsonObjectList":[{"value":"Audi","id":"Audi","label":"Audi"},{"value":"Mercedes","id":"Mercedes","label":"Mercedes"}]}
But I what I need (because it's Jquery UI autocomplete expected):
[{"value":"Audi","id":"Audi","label":"Audi"},{"value":"Mercedes","id":"Mercedes","label":"Mercedes"}]
How to achieve that? Thanks in advance.
Upvotes: 3
Views: 7690
Reputation: 43823
In Spring 3.1, you should be able to set a property on the MappingJacksonJsonView
bean called extractValueFromSingleKeyModel
to true
to remove the wrapper.
Oh, seems like this has been asked before Why is Jackson wrapping my objects with an extra layer named after the class?
Upvotes: 4