association subobject json POST Spring

I'm using spring boot and with this problem by sending the POST method when I have an association of another object.

Controller:

@RequestMapping(value="/save", method=RequestMethod.POST)
public @ResponseBody void save(@RequestBody Poultry poultry){ 

    repository.save(poultry);
}

Model:

public class Poultry {

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;

@NotEmpty
@Column(length = 100, nullable = false)
private String name;

private String token;

@ManyToOne
private Center center;

Url: http://localhost:8080/poultry/save Method: POST

Json:

{"id":null, "name": "123", "token":"1234", "center":{"id":2, "name":"Test"}}

Return method: 400 Bad Request

{ timestamp: 1435236955364 status: 400 error: "Bad Request" exception: "org.springframework.http.converter.HttpMessageNotReadableException" message: "Could not read JSON: Template must not be null or empty! (through reference chain: br.com.inobram.cdi.web.model.Poultry["center"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Template must not be null or empty! (through reference chain: br.com.inobram.cdi.web.model.Poultry["center"])" path: "/poultry/save" }

if execute method without object "center" return 200 OK

链接地址: http://www.djcxy.com/p/48524.html

上一篇: 通过邮递员在JSON中发送一个timstamp

下一篇: 关联子对象json POST Spring