How to use Jackson to deserialise a 2D Array
I am passing a 2D array JSON to a spring controller, but getting jackson
error.
org.codehaus.jackson.map.JsonMappingException:
Can not deserialize instance of java.lang.String[] out of
VALUE_NUMBER_INT token
My javascript 2D array looks like this.
[ ["John", "Doe", "worker", "fulltime"],
["Adam", "Smith", "nonworker", "temp"],
["Jane", "Doe", "worker", "fulltime"] ]
The bean class it gets mapped to 2D array like this.
public class MyBean implements java.io.Serializable {
private static final long serialVersionUID = -3948256457L;
String[][] workInfo = null;
public String[][] getWorkInfo() {
return workInfo;
}
public void setWorkInfo(String[][] workInfo) {
this.workInfo = workInfo;
}
public static long getSerialVersionUID() {
return serialVersionUID;
}
}
In the spring controller, I am using something like this.
public ModelAndView addData(@RequestBody MyBean tempForm) throws
Exception{
ModelAndView model = new ModelAndView(new
org.springframework.web.servlet.view.json.MappingJacksonJsonView());
try{
myService.addData(tempForm);
model.addObject("mesage", "success");
}
catch(Exception e)
{
model.addObject("mesage", "error");
log.error("error:"+e);
}
}
Can anyone suggest how can i resolve this issue.
No comments:
Post a Comment