springfox: Groovy metaClass not ignored when model is built for deserialization

    @RequestMapping(value = "/myresource", method = RequestMethod.GET)
    MyResource get() {
    }

    @RequestMapping(value = "/myresource", method = RequestMethod.POST)
    MyResource save(@Valid @RequestBody MyResource myResource) {
    }

When I have only “get”, in my controller - MyResource does not have metaClass. As soon as I add “save”, metaClass appears in both calls.

swagger-annotations:1.5.3-M1 swagger-model:1.5.3-M1 springfox-swagger2:2.0.0 jackson:2.4.5

Tracked to this code in BeanModelPropertyProvider:

  private BeanDescription beanDescription(ResolvedType type, ModelContext context) {
    if (context.isReturnType()) {
      SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
      return serializationConfig.introspect(TypeFactory.defaultInstance()
          .constructType(type.getErasedType()));
    } else {
      DeserializationConfig serializationConfig = objectMapper.getDeserializationConfig();
      return serializationConfig.introspect(TypeFactory.defaultInstance()
          .constructType(type.getErasedType()));
    }
  }

In both cases introspect returns metaClass description

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

exclude metaClass properties for groovy model classes in swagger: docket.ignoredParameterTypes(groovy.lang.MetaClass.class)

@aleksz have you used the guidance in the docs to configure the ObjectMapper? If you do it that way or create ObjectMapper using the Jackson2ObjectMapperBuilder you shouldn’t run into that issue.