java - Post to Spring Controller giving 404 Bad Request -


i have ajax call

$.ajax({       headers: {         'content-type': 'application/json'       },       url: urlstring,       type: 'post',       datatype: 'json',       data: json.stringify({          "field1": 1,          "field2": "foo",          "field3": "meh"       })       })       .done(function (datafromserver) {          //blah       })       .fail(function (jqxhr) {            console.log(jqxhr);       }); 

calling spring controller

@requestmapping(value="more/updatethistable", method=requestmethod.post) public void updatethistable(@requestbody string jsoninput) throws jsonprocessingexception, ioexception {     tabledto t;     tableimporter timp = null;     t= crewimp.gettabledto(jsoninput);     system.out.println(t);     tableservice.updatethistable(t); }; 

calls importer

public tabledto gettabledto(string json) throws jsonprocessingexception, ioexception{     tabledto tdto = new tabledto();     objectmapper mapper = new objectmapper();     jsonnode root = mapper.readtree(json);      tdto.setid(root.path("field1").asint());     tdto.setcrewgroupid(root.path("field2").astext());     tdto.setname(root.path("field3").astext());      return tdto; } 

i error message in browser console

"could not read json: can not deserialize instance of java.lang.string out of start_object token↵ @ [source: java.io.pushbackinputstream@124b300; line: 1, column: 1]; nested exception com.fasterxml.jackson.databind.jsonmappingexception: can not deserialize instance of java.lang.string out of start_object token↵ @ [source: java.io.pushbackinputstream@124b300; line: 1, column: 1]" 

i using jackson try go json java dto. getting error , don't know how fix.

ok - have code this:

@requestmapping(value="more/updatethistable", method=requestmethod.post, headers="accept=application/json") public void updatethistable(@requestbody tabledto t) throws jsonprocessingexception, ioexception {     system.out.println(t);     tableservice.updatethistable(t); }; 

also, f12 browser , view outgoing message make sure legit json.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -