Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Cygwin中的HTTP PUT请求中添加JSON作为消息体?_Java_Arrays_Json_Rest_Curl - Fatal编程技术网

Java 在Cygwin中的HTTP PUT请求中添加JSON作为消息体?

Java 在Cygwin中的HTTP PUT请求中添加JSON作为消息体?,java,arrays,json,rest,curl,Java,Arrays,Json,Rest,Curl,我有以下JSON,我已经使用它进行了验证: 我想在我的CURL命令中添加它作为消息体(使用Cygwin),以便测试我编写的REST处理程序 我当前正在使用此命令,该命令是我通过阅读创建的: 我的处理程序如下: @PUT @Consumes("application/json") @Path("/Id/{Id}/version/{version}/addPerson") public Response

我有以下
JSON
,我已经使用它进行了验证:

我想在我的
CURL
命令中添加它作为消息体(使用
Cygwin
),以便测试我编写的REST处理程序

我当前正在使用此命令,该命令是我通过阅读创建的:

我的处理程序如下:

            @PUT
            @Consumes("application/json")
            @Path("/Id/{Id}/version/{version}/addPerson")
            public Response addPerson(@PathParam("Id") String Id,
                                                    @PathParam("version") String version, 
                                                     @Context List<Name> names) {

            LOGGER.info("NAMES PASSED : {}", names.toString());

    }
@PUT
@使用(“应用程序/json”)
@路径(“/Id/{Id}/version/{version}/addPerson”)
公共响应addPerson(@PathParam(“Id”)字符串Id,
@PathParam(“版本”)字符串版本,
@上下文列表名称){
info(“传递的名称:{}”,NAMES.toString());
}
当我尝试使用CURL点击我的方法时,我得到了一个
htp400
方法

编辑:当我尝试执行names.toString()时,我得到一个空指针,这意味着名称列表必须为空

  • 不应使用
    @Context
    实体体(参数)应无注释

     public Response addPerson(@PathParam("Id") String Id,
                               @PathParam("version") String version, 
                               List<Name> names) {
    

  • {}
    在URL中不是有效字符。我建议您尝试使用邮递员应用程序而不是cURLtoo@cricket_007抱歉,我错误地添加了,请查看我使用的实际路径。我不知道您设置了什么json库,但
    @Context
    用于请求对象,而不是json文档。比如,看看这些例子,谢谢,请在回答中给出例子代码的变化,
                @PUT
                @Consumes("application/json")
                @Path("/Id/{Id}/version/{version}/addPerson")
                public Response addPerson(@PathParam("Id") String Id,
                                                        @PathParam("version") String version, 
                                                         @Context List<Name> names) {
    
                LOGGER.info("NAMES PASSED : {}", names.toString());
    
        }
    
     public Response addPerson(@PathParam("Id") String Id,
                               @PathParam("version") String version, 
                               List<Name> names) {
    
    curl -H "Content-Type: application/json" -X PUT -d '[
        {
            "id":"123",
            "name":"StubName",
            "type":"StubType",
        }
    ]' localhost:9980/Id/123/version/123/addPerson