Skip to content
Advertisement

OpenAPI @RequestBody variables of type Map are not populated

I’ve a simple POST API where the @RequestBody contains a variable of type HashMap.

The problem is that the variable “myMap” is never populated.

Swagger UI shows the entry field correctly, with corresponding default values. I also added the a static block in the Configuration file, otherwise Swagger UI doesn’t show the entry field of type Map.

What is needed so that the variable myMap is populated ?

Config class

JavaScript

Controller class

JavaScript

Swagger UI

enter image description here

pom.xml

JavaScript

Advertisement

Answer

I found out that I used the wrong annotation. @RequestBody is a class which resides in two packages :

  1. org.springframework.web.bind.annotation
  2. io.swagger.v3.oas.annotations.parameters

I used the annotation from package io.swagger.v3.oas.annotations.parameters which is wrong. The correct annotation is located in package org.springframework.web.bind.annotation

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement