Spring - 在另一个自定义对象的构造函数中传递自定义对象

时间:2015-05-07 22:07:51

标签: java json spring

我熟悉在春天以jsons的形式发送和返回数据,但我无法弄清楚如何将另一个自定义对象作为参数从客户端传递到REST Web服务。

我的控制器:

@RequestMapping(value = "/new", method = RequestMethod.POST)
public ResponseEntity<Person> create(@RequestBody Person person) throws BaseException {
    person.validate();
    personList.add(person);
    return new ResponseEntity(HttpStatus.CREATED);
}

我正在传递的json:

{
"firstName": "john",
"lastName": "smith",
"birthDate": {
    "month": 3,
    "day": 30,
    "year": 1984
},
"gender": false
}

和我的对象的构造:

public Person(String firstName, String lastName, BirthDate birthDate, boolean gender) throws BaseException {
    //set values
}

public BirthDate(int month, int day, int year) throws InvalidBirthDateException {
    //set values
}

但这不起作用,我收到错误

  

400客户端发送的请求在语法上是不正确的。

任何人都知道如何做到这一点?

0 个答案:

没有答案