java - Getting "The request sent by the client was syntactically incorrect" when parsing the following JSON using Spring REST and Jackson -
using spring 4 , jackson 1.9.13, when making rest call getting error saying "the request sent client syntactically incorrect" , call doesn't enter rest method...
json array of arrays format:
[ "location", [ { "regions":[], "x":10.0, "y":14.0, "timeexpires":1387219731911, "confidence":0.9, "timestamp":1387219671911, "source":"wifi", "associated":true, "clientmac":"1c:4f:2b:14:c9:8b", "clienttype":"abc device", "adspnetworkpath":"/a/b/c1", "folderid":10007, "floornumber":1, "timecomputed":1387219671911 }, { "regions":[], "x":8.222222, "y":18.88889, "timeexpires":1387219726912, "confidence":0.9, "timestamp":1387219666912, "source":"wifi", "associated":true, "clientmac":"64:a3:ab:6b:5d:4f", "clienttype":"123 device", "adspnetworkpath":"/a/b/d1", "folderid":10007, "floornumber":1, "timecomputed":1387219666912 } ] ]
the spring controller looks like:
@requestmapping(value="/location", method=requestmethod.post) public @responsebody void locationdata(@requestbody list<location> locationlist) { logger.info("inside locationdata() method..."); objectmapper mapper = new objectmapper(); try { // convert list of object , display now... string jsonstring = mapper.writevalueasstring(locationlist); logger.info(jsonstring); } catch (ioexception e) { e.printstacktrace(); } }
the model object having problem.
package com.tester; import java.util.list; import org.codehaus.jackson.annotate.jsonproperty; public class location { private string location; private list<adspdata> locationarray; @jsonproperty(value = "location") public string getlocation() { return location; } public void setlocation(string location) { this.location = location; } @jsonproperty(value = "location-array") public list<adspdata> getlocationarray() { return locationarray; } public void setlocationarray(list<data> locationarray) { this.locationarray = locationarray; } @override public string tostring() { return "location [location=" + location + ", locationarray=" + locationarray + "]"; } }
other model class:
package com.tester; import java.util.arraylist; import java.util.date; import org.codehaus.jackson.annotate.jsonproperty; import org.codehaus.jackson.map.annotate.jsonserialize; import com.tester.util.jsondateserializer; public class adspdata { private arraylist<string> regions; private double xloc; private double yloc; private double confidence; private date timeexpires; private date timestamp; private date timecomputed; private string source; private string clientmac; private string clienttype; private string adspnetworkpath; private int folderid; private int floornumber; private boolean associated; public adspdata() { } @jsonproperty(value = "regions") public arraylist<string> getregions() { return regions; } public void setregions(arraylist<string> regions) { this.regions = regions; } @jsonproperty(value = "x") public double getxloc() { return xloc; } public void setxloc(double xloc) { this.xloc = xloc; } @jsonproperty(value = "y") public double getyloc() { return yloc; } public void setyloc(double yloc) { this.yloc = yloc; } @jsonproperty(value = "confidence") public double getconfidence() { return confidence; } public void setconfidence(double confidence) { this.confidence = confidence; } @jsonproperty(value = "timeexpires") @jsonserialize(using = jsondateserializer.class) public date gettimeexpires() { return timeexpires; } public void settimeexpires(date timeexpires) { this.timeexpires = timeexpires; } @jsonproperty(value = "timestamp") @jsonserialize(using = jsondateserializer.class) public date gettimestamp() { return timestamp; } public void settimestamp(date timestamp) { this.timestamp = timestamp; } @jsonproperty(value = "timecomputed") @jsonserialize(using = jsondateserializer.class) public date gettimecomputed() { return timecomputed; } public void settimecomputed(date timecomputed) { this.timecomputed = timecomputed; } @jsonproperty(value = "source") public string getsource() { return source; } public void setsource(string source) { this.source = source; } @jsonproperty(value = "clientmac") public string getclientmac() { return clientmac; } public void setclientmac(string clientmac) { this.clientmac = clientmac; } @jsonproperty(value = "clienttype") public string getclienttype() { return clienttype; } public void setclienttype(string clienttype) { this.clienttype = clienttype; } @jsonproperty(value = "adspnetworkpath") public string getadspnetworkpath() { return adspnetworkpath; } public void setadspnetworkpath(string adspnetworkpath) { this.adspnetworkpath = adspnetworkpath; } @jsonproperty(value = "folderid") public int getfolderid() { return folderid; } public void setfolderid(int folderid) { this.folderid = folderid; } @jsonproperty(value = "floornumber") public int getfloornumber() { return floornumber; } public void setfloornumber(int floornumber) { this.floornumber = floornumber; } @jsonproperty(value = "associated") public boolean isassociated() { return associated; } public void setassociated(boolean associated) { this.associated = associated; } @override public string tostring() { return "adspdata [regions=" + regions + ", xloc=" + xloc + ", yloc=" + yloc + ", confidence=" + confidence + ", timeexpires=" + timeexpires + ", timestamp=" + timestamp + ", timecomputed=" + timecomputed + ", source=" + source + ", clientmac=" + clientmac + ", clienttype=" + clienttype + ", adspnetworkpath=" + adspnetworkpath + ", folderid=" + folderid + ", floornumber=" + floornumber + ", associated=" + associated + "]"; } }
it should this.
[ { "location": "location data", "locationarray": [ { "regions": [], "x": 10.0, "y": 14.0, "timeexpires": 1387219731911, "confidence": 0.9, "timestamp": 1387219671911, "source": "wifi", "associated": true, "clientmac": "1c:4f:2b:14:c9:8b", "clienttype": "abc device", "adspnetworkpath": "/a/b/c1", "folderid": 10007, "floornumber": 1, "timecomputed": 1387219671911 }, { "regions": [], "x": 8.222222, "y": 18.88889, "timeexpires": 1387219726912, "confidence": 0.9, "timestamp": 1387219666912, "source": "wifi", "associated": true, "clientmac": "64:a3:ab:6b:5d:4f", "clienttype": "123 device", "adspnetworkpath": "/a/b/d1", "folderid": 10007, "floornumber": 1, "timecomputed": 1387219666912 } ] } ]
Comments
Post a Comment