question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Groovy metaClass not ignored when model is built for deserialization

See original GitHub issue
    @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

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

8reactions
fitzfcommented, Jul 4, 2017

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

1reaction
dilipkrishcommented, Jun 17, 2015

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Metaprogramming
The Groovy language supports two flavors of metaprogramming: runtime and compile-time. The first allows altering the class model and the ...
Read more >
Jackson @JsonIgnoreProperties isn't working on referenced ...
And I was told that I cannot modify referenced model ( User ) in any way, so what I had tried was to...
Read more >
Java Deserialization Tool Gadgetinspector First Glimpse
This tool will generate false positives and not false negatives (in fact, it will still be missed, which is determined by the strategy...
Read more >
Metaprogramming in Groovy - Baeldung
Metaprogramming is a programming technique of writing a program to modify itself or another program using metadata. In Groovy, it's possible ...
Read more >
4. User Guides - Groovy Language Documentation
All these packages and classes are imported by default, i.e. you do not have ... In Java, this is the opposite: methods are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found