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.
In Spring 3.1, you should be able to set a property on the
MappingJacksonJsonViewbean calledextractValueFromSingleKeyModeltotrueto 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?