I have a DTO object like this:
data class ClientDto(
var uuid: String,
var ip: String,
var lastSeen: Date? = Date()
) {
internal fun toEntity() = Client(uuid=uuid, ip=ip, lastSeen=Date())
}
... and a controller like this:
@RestController
internal class ClientController {
@Autowired
private lateinit var service : ClientService
@GetMapping("/clients")
internal fun getClients() = service.findAll()
@PostMapping("/clients")
internal fun postClient(@RequestBody client: ClientDto) = service.add(client)
}
Now I post with httpie something like this:
http POST localhost:8080/clients uuid=my-uuid ip=192.123.31:8080
And get:
{
"error": "Bad Request",
"exception": "org.springframework.http.converter.HttpMessageNotReadableException",
"message": "JSON parse error: Can not construct instance of awesome.discovery.domain.dto.ClientDto: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of awesome.discovery.domain.dto.ClientDto: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)\n at [Source: java.io.PushbackInputStream@71c6ae97; line: 1, column: 2]",
"path": "/clients",
"status": 400,
"timestamp": 1519587678605
}
- What is wrong with this post?
- More importantly how can I debug this, e.g. know what it tries and how to get to understand where it goes wrong?