java - Postman 中仅显示响应实体

标签 java jersey jax-rs postman

我有一个响应,它产生 @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/

相关文章:

java - ResourceConfig实例不包含任何根资源类

java - 使用 JAX-RS 将两个查询参数合并到一个对象中

java - JAX-RS 编码

java - ScrollView 不是从顶部开始

Java:使用库将文件从 URL 直接上传到 FTP 服务器

java - 将 Jersey 服务实例发布到 Grizzly

java - JSON - 将 JSON 字符串放入 JSON 对象时出错

json - JAX-RS/Jackson -- 使用未知的根元素名称反序列化 JSON?

java - 如何使用 java 8 流将 float ArrayList 转换为原始 float 数组?

java - 如何从JAVA中混合有字符的文件中读取整数?