javascript オブジェクトを JAX-RS サーバーに送信しようとしています。jquery から PUT すると、サーバー側の例外が発生します。
これが私のサーバーコードです
//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
なにか提案を ?
どうも