我有一个响应,它产生 @Produces(MediaType.APPLICATION_JSON)
如下:
return Response.status(200).entity(product).entity("some message").build();
为什么 postman 在 json View 结果中显示意外的
并在 xml View 中显示一些消息
最佳答案
对于Response.ResponseBuilder.entity(Object)`你可以看到
public abstract Response.ResponseBuilder entity(Object entity)
Set the response entity in the builder. Any Java type instance for a response entity, that is supported by the runtime can be passed. It is the callers responsibility to wrap the actual entity with GenericEntity if preservation of its generic type is required. Note that the entity can be also set as an input stream.
A specific entity media type can be set using one of the type(...) methods.
由于您调用此方法两次,因此仅保存最后一个值。
由于“some message”根本不是 JSON 语法,因此它表示 s(来自 some)是意外的,它需要一个 {
关于java - Postman 中仅显示响应实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42275716/