Jax-rs(Jersey)消耗POST请求中的Json对象数组

LOK*_*LOK 10 java rest jax-rs jersey

使用jax-rs(Jersey)我尝试实现一个带有JSON对象列表的POST请求

//The resource look like this
@Path("/path")
@POST
@Consumes(MediaType.APPLICATION_JSON)
public void setJsonl(List<SomeObj> test) {
  //do work
  System.out.println(test);
}


//The class to define the json structure
@XmlRootElement
public class SomeObj{

private String tag;
private String value;

public String getTag() {
 return tag;
}

public void setTag(String tag) {
  this.tag = tag;
}

public String getValue() {
  return value;
}

public void setValue(String value) {
  this.value = value;
}
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用curl测试REST api时,我总是遇到"错误的请求"错误,我在这里遗漏了什么?

curl -X POST -H "Content-Type: application/json" -d '{"SomeObj":[{"tag":"abc", "value":"ghi"},{"tag":"123", "value":"456"}]}' http://{host_name}:8080/path_to_resource
Run Code Online (Sandbox Code Playgroud)

use*_*174 4

如果您不介意更改方法的签名:

import org.json.JSONArray;

    //The resource look like this
    @Path("/path")
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    public void setJsonl(String array){
        JSONArray o = new JSONArray(last_data);
        System.out.println(o.toString());
Run Code Online (Sandbox Code Playgroud)