0

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..

Thiyagu
  • 17,362
  • 5
  • 42
  • 79

1 Answers1

1

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();
Avalanche
  • 386
  • 2
  • 10