i have the following server side Java Code which works perfectly for my chrome-rest-client:
@POST
@Consumes(MediaType.APPLICATION_JSON)
public long postVehicle(Vehicle vehicle) {
vehicleDao.persist(vehicle);
return vehicle.getId();
}
i can send an JSON via my rest-client to test this interface and it gets processed very well.
But now i want to send the following json via an web-page with a jQuery-ajax request to my server:
var data = {
"color": "black",
"emissionStandards": "EURO 5",
"emptyWeight": "1500",
"mileage": "60000",
"topSpeed": "260"
}
var options = {
url: "resources/vehicle",
data: data,
contentType: "application/json",
dataType: "json",
processData: false,
type : "POST",
success: callback,
async: true
};
$.ajax(options);
the request-headers which i see in my debugger looks good to me.
But i get the following two errors from the server:
org.glassfish.jersey.server.ContainerException: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of de.ibs.trail.entity.Vehicle out of START_ARRAY token
org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of de.ibs.trail.entity.Vehicle out of START_ARRAY token
EDIT 1::
I tried it with an jQuery-Rest-Client and it also didn't work
md.rest = new $.RestClient('/trail/resources/', {ajax: {processData: false, DataType: 'json', contentType: 'application/json'}});
md.rest.add("vehicle");
var data = {/* same data as above */};
md.rest.vehicle.create(data); //same data as my first try
same errors
EDIT 2::
Here is the raw-request-header
POST /resources/vehicle/ HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 329
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://localhost:8080
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36
Content-Type: application/json
DNT: 1
Referer: http://localhost:8080/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Cookie: JSESSIONID=f5a663a3743657defb5c13aef866; treeForm_tree-hi=treeForm:tree:applicationServer
And the payload:
'{"color": "black","emissionStandards": "EURO 5","emptyWeight": "1500","mileage": "60000","topSpeed": "260"}'