Reputation: 17890
I have a list which I want to return as a Response. But I want to prepend it with a field name.
List<String> res = ...
return Response.ok(res, MediaType.APPLICATION_JSON_TYPE).build();
This returns only the list
["abcd","efgh"]
But I want to return like
{
"field" : ["abcd","efgh"]
}
Thanks..
Upvotes: 0
Views: 1632
Reputation: 386
Use a map.
List<String> list = ...
Map<String, List<String>> res = new HashMap<>();
res.put("field", list);
return Response.ok(res, MediaType.APPLICATION_JSON_TYPE).build();
Upvotes: 1