How do we exclude metaclass properties in model for "groovy" classes as Response? I have a Jax-Rs resource which returns a groovy object annotated with swagger @ApiModel. I see too many groovy specific attributes in swagger ui. How do I exclude it from serialization?
@EqualsAndHashCode
@Document(collection = 'MongoCollection')
@CompileStatic
@ToString
@XmlRootElement
@XmlAccessorType(value = XmlAccessType.FIELD)
@ApiModel(value = "Represents a document from mongo collection")
class Foo {
..
..
}
It seems to be using Jackson for pogo-json serialization? How do annotate my groovy class to exclude metaclass properties from getting into json serialized string? I tried using JsonIgnoreProperties annotation but it didnt help.
@JsonIgnoreProperties(ignoreUnknown = true, value = ["MetaClass","MetaMethod"])
If using springfox, see springfox issues 752, found a way to resolve this :
docket.ignoredParameterTypes(groovy.lang.MetaClass.class)
A code example is:
@Configuration
public class SpringFoxConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.ignoredParameterTypes(groovy.lang.MetaClass.class)
.select()
.apis(RequestHandlerSelectors.any())
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.build();
}
}
https://springdoc.org/#groovy-support
Including this dependency with the springdoc-openapi-ui dependency will resolve the issue in the newer versions.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-groovy</artifactId>
<version>1.6.13</version>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With