我有 REST 服务。 GET方法的输入类型为List<String>
:
@GET
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public List<myObject> getData(List<String> IDs) {
....
}
我尝试使用curl来测试这个方法。我使用了很多不同的数据组合:
curl -X GET --data-binary '{"IDs":["TestString1","TestString2"]}' -H "Content-Type: application/json" http://localhost:8080/myModule/rs/getData -v
'{"TestString1","TestString2"}'
'["TestString1","TestString2"]'
so on
但我总是得到回应:
Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
or
Can not deserialize instance of java.util.ArrayList out of VALUE_STRING token
是否可以输入List<String>
?我的curl请求不正确吗?
最佳答案
看起来您是sending a POST request :
--data-binary < data>
(HTTP) This posts data exactly as specified with no extra processing whatsoever.
自 -X
sets a custom request type ,我猜它没有检测到需要对数据进行 URL 编码:
-X, --request < command>
(HTTP) Specifies a custom request method to use when communicating with the HTTP server. The specified request will be used instead of the method otherwise used (which defaults to GET). Read the HTTP 1.1 specification for details and explanations. Common additional HTTP requests include PUT and DELETE, but related technologies like WebDAV offers PROPFIND, COPY, MOVE and more.
所以尝试使用 -G
相反:
-G, --get
When used, this option will make all data specified with -d, --data or --data-binary to be used in an HTTP GET request instead of the POST request that otherwise would be used. The data will be appended to the URL with a '?' separator.
关于java - List<String> 作为 GET 方法的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13573874/