简体   繁体   中英

Spring mvc mapping json to pojo properties are null

A Rest service is mapped on one url with some @RequestBody where i am mapping json to pojo. Pojo contains nested classes following is sample code.

@RequestMapping(value = "/saveExampleObject.html", method = RequestMethod.POST)
public @ResponseBody List<String> saveExampleObjectDefintion(@RequestBody ExampleObject exampleObject) throws DataAccessException,DataNotPersistException {
    List<String> msg = saveService.save(exampleObject);
    return msg;
}

and the object is like

class ExampleObject{
String name;
SubClass subClass;
.....
}

and json is

{
"name":"name",
"subClass":{
.....
}

I have configured spring mvc annotation and conversion is also happening. But some fields are null . I cross checked names of null field they are same as in json and pojo.

PS Only first fields are getting values in subclass.Thanks.

在你的json中你有subClass但在你的类中你有子类...区分大小写

Here the setters were not defined properly and hence there was an error. Spring MVC uses the setters to properly convert POJO to JSON and vice versa.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM