title: How to custom convert String to enum in @RequestBody?
body: <p>I want to send a JSON request body where fields can be enum values. These enum values are in camelCase, but the enum values are UPPER_SNAKE_CASE.</p>
  
  <p>Kotlin classes:</p>
  
  <pre><code>data class CreatePersonDto @JsonCreator constructor (
          @JsonProperty("firstName") val firstName: String,
          @JsonProperty("lastName") val lastName: String,
          @JsonProperty("idType") val idType: IdType
  )
  </code></pre>
  
  <pre><code>enum class IdType {
      DRIVING_LICENCE,
      ID_CARD,
      PASSPORT;
  }
  </code></pre>
  
  <p>My endpoint signature:</p>
  
  <pre><code>@PostMapping
  fun createPerson(@RequestBody person: CreatePersonDto)
  </code></pre>
  
  <p>HTTP request:</p>
  
  <pre><code>curl -d '{ "firstName": "King", "lastName": "Leonidas", "idType": "drivingLicence" }' -H "Content-Type: application/json" -X POST http://localhost:8080/person
  </code></pre>
  
  <p>I want to convert "drivingLicence" to DRIVING_LICENCE implicitly.</p>
  
  <h1><strong>I have tried:</strong></h1>
  
  <ul>
  <li><code>org.springframework.core.convert.converter.Converter</code>: It works for <code>@RequestParam</code>, but not for <code>@RequestBody</code></li>
  <li><code>org.springframework.format.Formatter</code>: I registered this formatter, but when I make the request the <code>parse()</code> method is not executed.</li>
  </ul>
  
  <p>My configuration so far:</p>
  
  <pre><code>@Configuration
  class WebConfig : WebMvcConfigurer {
  
      override fun addFormatters(registry: FormatterRegistry) {
          registry.addConverter(IdTypeConverter())
          registry.addFormatter(IdTypeFormatter())
      }
  }
  </code></pre>