Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exclude metaclass properties for groovy model classes in swagger

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"])
like image 834
suman j Avatar asked Dec 14 '25 01:12

suman j


2 Answers

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();
        }
    }
like image 182
btpka3 Avatar answered Dec 18 '25 04:12

btpka3


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>
like image 45
Raytray Avatar answered Dec 18 '25 03:12

Raytray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!