java - 如何使用 jersey REST Webtarget API 发布对象的 json 列表?- 得到错误 MessageBodyWriter not found
问题描述
我可以使用以下代码发送单个对象:
Entity<User> body = Entity.json(user);
Response response = webTarget.path("/singleuser")
.request(MediaType.APPLICATION_JSON)
.post(body);
但是,这不起作用:
Entity<List<User>> body = Entity.json(users);
Response response = webTarget
.path("/multipleusers")
.request(MediaType.APPLICATION_JSON)
.post(body);
我收到以下错误:
MessageBodyWriter not found for media type=application/json, type=class java.util.ArrayList, genericType=class java.util.ArrayList
解决方案
不确定这是否可行,但您可以尝试使用数组而不是列表。
Entity<User[]> body = Entity.json(users);
Response response = webTarget
.path("/multipleusers")
.request(MediaType.APPLICATION_JSON)
.post(body);
推荐阅读
- mysql - 在 Node.js 和 Mysql 中按月过滤数据
- javascript - 限制表中的数据数量
- c++ - 将 char* 转换为 c++ 中的结构
- javascript - 在 Yii2 上使用 lib CountUp.js
- excel - 在特定工作表上运行 VBA
- node.js - 如何访问打字稿中方法的所有参数?
- ansible - Make a file executable with Ansible, then make Ansible execute it
- javascript - 如何将 javascript 文件转换为 .exe 文件
- r - GGplot将“单词”添加到y轴标签
- python - 根据条件对数据子集进行模糊处理