title: How to tweak the Spring MVC or @RequestBody behaviour to parse json files with and without root elements
body: <p>Using <code>Spring Boot 2.6.4</code>, I am trying to tweak the behavior of the <code>@RequestBody</code> to parse json requests with or without Root elements without writing boilerplate code in the same controller class.</p>
  <pre><code>//should emulate the behaviour of the ObjectMapper when the property is set as 'spring.jackson.deserialization.UNWRAP_ROOT_VALUE=false'
  
  @PostMapping(value = &quot;/method&quot;) public void method1(@RequestBody SomeObject someObject) { 
  
  }
  </code></pre>
  <pre><code>//should emulate the behaviour of the ObjectMapper when the property is set as 'spring.jackson.deserialization.UNWRAP_ROOT_VALUE=true'
  
  @PostMapping(value = &quot;/method&quot;)
  public void method1(@RequestBody SomeObject someObject) {
  
  }
  </code></pre>
  <p>This is the boilerplate option.</p>
  <pre><code>@PostMapping(value = &quot;/method2&quot;)
  public void method(@RequestBody String jsonString) {
  try {
        ObjectMapper mapper = new ObjectMapper();
        mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
  
        SomeObject someObject = mapper.readValue(jsonString, SomeObject.class);
          //proceed to business logic
      } catch (JsonProcessingException jsonProcessingException) {
      }
  </code></pre>