title: Using Kotlin data class to group path variables in a Spring @RequestMapping annotated method
body: <p>Currently I am trying to reduce the number of parameters on @RequestMapping annotated methods in a class annotation with @RestController using kotlin data classes. Also I don't want to repeat myself on multiple @RequestMapping annotated methods which contain the same path variables.</p>
  
  <p>The code below shows my approach where <code>/multiple/ABC/true/123</code> works as expected but <code>/single/ABC/true/123</code> complains about a missing default constructor. </p>
  
  <pre><code>data class Params(@PathVariable("param1") val param1: String,
                    @PathVariable("param2") val param2: Boolean,
                    @PathVariable("param3") val param3: Int)
  
  @RestController
  class TestController {
     @RequestMapping("/single/{param1}/{param2}/{param3}")
     fun single(params: Params) {
         println(listOf(params.param1, params.param2, params.param3))
     }
  
     @RequestMapping("/multiple/{param1}/{param2}/{param3}")
     fun multiple(@PathVariable("param1") param1: String,
                  @PathVariable("param2") param2: Boolean,
                  @PathVariable("param3") param3: Int) {
         println(listOf(param1, param2, param3))
     }
  }
  </code></pre>
  
  <p>When I use the following data class definition instead I get a result but then the instance isn't immutable anymore and may have some fields not updated.</p>
  
  <pre><code>data class Params(@PathVariable("param1") var param1: String = "",
                    @PathVariable("param2") var param2: Boolean = false,
                    @PathVariable("param3") var param3: Int = 0)
  </code></pre>
  
  <p>Can anyone help me making the first data class definition work?</p>