I have some API defined using Spring codegen, and the snippet for @ApiResponse is defined below:
@ApiResponse(responseCode = "201", description = "Created successfully", content = @Content(mediaType = "application/json", schema = @Schema(implementation = Money.class)))
The schema Money. class uses different serializers, deserializers, and mixins.
I am using the below Springdoc dependency to generate the docs automatically:
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.7.0</version>
</dependency>
This is doing the purpose, but the example schema and example value in Swagger UI for POST are incorrect. The mixins are applied successfully but the JacksonAnnotationIntrospector, @JsonTypeInfo is not being applied. When I use the "try it out" functionality of Swagger, the POST request fails because the example body automatically created by Swagger does not use appropriate JacksonAnnotationIntrospector.
The problem is that it should apply JacksonAnnotationIntrospector for serialization, which is already provided. I have used below ModelResolver bean to define the custom ObjectMapper, but still, it is working for mixins only:
@Bean
public ModelResolver modelResolver(Jackson2ObjectMapperBuilder builder) {
ObjectMapper mapper = builder.build();
return new ModelResolver(mapper);
}
Spring Boot Version: 2.7.10
Can anybody help me to solve this?