'Spring-Fox doesn't support Jackson's @JsonTypeName annotation on Swagger-UI

I've a SpringBoot based server (v2.2.2.RELEASE very old) that uses springfox-boot-starter:v3.0.0

I have few beans that are used as response in @RestController.

Here is a snippet of this response Pojo:

@JsonTypeName(value = "getUser")
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME)
public class GetUserResponse {

  private final long userId;

  public GetUserResponse(long userId) {
    this.userId = userId;
  }

  @JsonProperty("uId")
  public long getUserId() {
     return userId;
  }

  ...
}

I run the server go to the swagger page and look at this endpoint, the response look like this:

{
   "uId": 0
}

What I expect to see is:

{
  "getUser" : {
    "uId" : 0
  }
}

For some reason Swagger doesn't parse the JsonTypeName nor JsonTypeInfo annotations thus doesn't add the root node to the response.

It is important to say that if I actually run the API then the response does contain the root node!! the problem only occurs when looking the structure of the response in the Swagger UI.

I also tried to work with @JsonRootName annotation but that really broke the Swagger and I couldn't even load Swagger-UI page.

Any idea how to make this works??



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source