Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.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 使用JQuery和JSON向JAX-RS发送对象时出错_Java_Javascript_Jquery_Jax Rs - Fatal编程技术网

Java 使用JQuery和JSON向JAX-RS发送对象时出错

Java 使用JQuery和JSON向JAX-RS发送对象时出错,java,javascript,jquery,jax-rs,Java,Javascript,Jquery,Jax Rs,我正在尝试向JAX-RS服务器发送一个javascript对象。当我从jquery中输入时,我得到一个服务器端异常 这是我的服务器代码 //JAX-RS Server @PUT @Path("/edit/{project_key}/") @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) public Response editAssociation(@PathParam("project_key") Stri

我正在尝试向JAX-RS服务器发送一个javascript对象。当我从jquery中输入时,我得到一个服务器端异常

这是我的服务器代码

//JAX-RS Server
@PUT
@Path("/edit/{project_key}/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response editAssociation(@PathParam("project_key") String projectKey,
    @FormParam("association") EditFieldAssociationModel association) {
        //TODO
        //Here i just put a debug break point
        return Response.noContent().build();
}

//EditFieldAssociationModel class    
@XmlRootElement(name = "EditFieldAssociationModel")
@XmlAccessorType(XmlAccessType.FIELD)
public class EditFieldAssociationModel {
    @XmlElement(name = "id")
    private Long id;

    @XmlElement(name = "method")
    private String method;

    @XmlElement(name = "jiraDefaultValue")
    private String jiraDefaultValue;

    @XmlElement(name = "externalDefaultValue")
    private String externalDefaultValue;

    //and public accessors
}
和我的js代码:

function(){
    var editasso = {id:asso_id,
            method:d.find(".sync-plugin-method").find('select').val(),
            jiraDefaultValue:d.find('.sync-plugin-jira-default-value').find('select').val(),
            externalDefaultValue:d.find('.sync-plugin-external-default-value').find('select').val()};

    AJS.$.ajax({
          url: AJS.contextPath()+"/rest/a-sync-rest/1.0/association/edit/"+getProjectKey(),
          type: "PUT",
          //TODO

          data: JSON.stringify(editasso),
          beforeSend: function(x) {
                if (x && x.overrideMimeType) {
                  //x.overrideMimeType("application/json; charset=UTF-8");
                  x.setRequestHeader("Content-type", "application/json; charset=UTF-8");
                  console.log("mime type override ok");
                }else{
                    console.log("unable to override mime type");
                }
           },
          dataType: "json",
          success: function(msg){
              dialog.remove();
              location.reload();
          },
          error : sync_plugin_error
    });
}
我为editasso尝试了其他值

var editasso = {association : {id:asso_id,
                        method:d.find(".sync-plugin-method").find('select').val(),
                        jiraDefaultValue:d.find('.sync-plugin-jira-default-value').find('select').val(),
                        externalDefaultValue:d.find('.sync-plugin-external-default-value').find('select').val()}};
帖子的主体似乎是正确的:

{"association":{"id":"350","method":"com.a.jira.synchronization.KeepLatestSyncMethod","jiraDefaultValue":"Valeur 1","externalDefaultValue":"aa"}}
例外是

org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
有什么建议吗


问题已解决:EditFieldAssociationModel不能使用与server to client类相同的注释。现在,我的班级看起来像:

public class EditFieldAssociationModel {
    @JsonProperty("id")
    private Long id;

    @JsonProperty("method")
    private String method;

    @JsonProperty("jiraDefaultValue")
    private String jiraDefaultValue;

    @JsonProperty("externalDefaultValue")
    private String externalDefaultValue;

    //getters and setters
}
它是有效的