![](/img/trans.png)
[英]Jersey REST error, MessageBodyWriter not found for media type=application/json
[英]How do you POST a json list of objects using the jersey REST Webtarget API? - getting error 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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.