Receber um Json e converter em objeto no Spring 4 + Jackson
Bom dia, estou precisando de uma ajudinha, onde quero receber um Json e converter o mesmo em um objeto no Spring 4 + Jackson, onde a requisição é realizada via POST. Estou recebendo a requisição mais esta retornando o seguinte error:
Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of br.com.lojavirtual.entity.Person: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: java.io.PushbackInputStream@3e64cd8; line: 1, column: 2]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of br.com.lojavirtual.entity.Person: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: java.io.PushbackInputStream@3e64cd8; line: 1, column: 2]
Minha
Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not construct instance of br.com.lojavirtual.entity.Person: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: java.io.PushbackInputStream@3e64cd8; line: 1, column: 2]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of br.com.lojavirtual.entity.Person: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: java.io.PushbackInputStream@3e64cd8; line: 1, column: 2]
@RequestMapping(value="/person",method=RequestMethod.POST,produces="application/json")
public String loadPerson(@RequestBody Person json){
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> map = mapper.readValue(json,Person.class);
return person.toString();
}
Minha
<dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.8.6</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.8.6</version> </dependency>
Glêsio Santos
Curtidas 0