簡體   English   中英

您如何使用 jersey REST Webtarget API 發布對象的 json 列表? - 未找到錯誤 MessageBodyWriter

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM