Alex
10/08/2020, 12:17 PM@PostMapping("/")
fun addAnnouncement(@RequestBody dto: AnnouncementDTO) {
println(dto);
manager.addAnnouncement(dto.toAnnouncement())
}
This is my body:
{
"text": "Hello",
"occupant": "35A",
"date": "2020-10-09"
}
It works.
Second question: Why?
I'm assuming this might not be even a kotlin-specific question, rather Spring, but as I said, I'm quite new at this so excuse some confusion. 🙂thanksforallthefish
10/08/2020, 12:53 PMAlex
10/08/2020, 12:54 PMthanksforallthefish
10/08/2020, 12:54 PMAlex
10/08/2020, 1:02 PMRequestResponseBodyMethodProcessor
which processes all the requests.
In in there's a method called readWithMessageConverters
which calls it's parent (from the abstract class) that contains a bunch of converters (this.messageConverters
) - an array of various converters that have a canRead
method. At some point AbstractJackson2HttpMessageConverter
is invoked and canDeserialize
method is checked. After that a converter is invoked and Jackson takes over and converts it to the class.Chris Black
10/08/2020, 5:14 PM