Spring MVC + binding request params to immutable kotlin classes


#1

Hello there,

I’m experimenting a bit with implementing REST apis using Spring and Kotlin and I’m wondering whether it is possible to avoid mutability in case of binding @RequestParams, @PathVariables that are encapsulated in separated class.

Example situation:

@PostMapping("/api/{name}") fun getVersion(request: Request, @RequestBody reqBody: ReqBody): String { return "1.0" }

Are you aware of any way how to generally speaking force Spring to inject these values via constructor, instead of getters/setters+empty constructor?

I know that this is already possible in case of Jackson. Thanks for any hints!