如果实体只是一个List tokenList那么这一行
return Response.status(Response.Status.OK).entity(tokenList).build();
将返回
{“ArrayList”:[“c2171488”]}
如果我改变
GenericEntity entity = new GenericEntity<List<String>>(tokenList) {}
我有
{“列表”:[“c2171488”]}
我想要的是将JSON响应中的名称更改为“token”,因此它看起来应该是这样的
{“Token”:[“c2171488”]}
有一个简单的方法吗?
ResponseBuilder实体函数有一个带有Annotation的变体,但是没有我能找到的例子。 qazxsw poi
找到了解决方案
String results = objectMapper.writeValueAsString(Collections.singletonMap(“Token”,tokenIdList)); return Response.status(Response.Status.OK).entity(results).build();