Swagger-core: Swagger fails on response type of ObjectNode

Created on 23 May 2016  路  7Comments  路  Source: swagger-api/swagger-core

Several of our REST APIs return ObjectNode as a free-form JSON object. JAXRS handles this cleanly. However, swagger fails to initialize in this scenario with the following error:

java.lang.IllegalArgumentException: Conflicting setter definitions for property "all": com.fasterxml.jackson.databind.node.ObjectNode#setAll(1 params) vs com.fasterxml.jackson.databind.node.ObjectNode#setAll(1 params)
    at com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder.getSetter(POJOPropertyBuilder.java:320)
    at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:267)
    at io.swagger.jackson.ModelResolver.resolve(ModelResolver.java:149)

It would be nice for swagger to not to be completely unusable in this scenario. For example, the implementation could special case ObjectNode response types and document as a schema-less response object.

Most helpful comment

Thx a lot for the workaround @StevenChoo!!

All 7 comments

Hi guys, Any workaround for this @sirianni?

@borillo

Today,I ran also into this problem by coincidence. Unfortunately I can`t spend lots of time atm looking for the correct fix, but as a quick workaround that seems to work is to manually override the version of the Jackson libraries using maven.

Maybe to need to try several versions. 2.7.4 didn`t work but 2.5.4 for some reason does. I will check later what the difference is in the source code.

The proper fix for this project would be to update the version of Jackson

example of the fix in the pom.xml using Maven:

<dependencies>
   <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-jaxrs</artifactId>
      <exclusions>
         <exclusion>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-jaxb-annotations</artifactId>
         </exclusion>
         <exclusion>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-xml</artifactId>
         </exclusion>
         <exclusion>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
         </exclusion>
         <exclusion>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
         </exclusion>
         <exclusion>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
         </exclusion>
         <exclusion>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
         </exclusion>
         <exclusion>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
         </exclusion>
         <exclusion>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-joda</artifactId>
         </exclusion>
         <exclusion>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-base</artifactId>
         </exclusion>
      </exclusions>
   </dependency>
   <dependency>
      <groupId>com.fasterxml.jackson.module</groupId>
      <artifactId>jackson-module-jaxb-annotations</artifactId>
      <version>2.5.4</version>
   </dependency>
   <dependency>
      <groupId>com.fasterxml.jackson.dataformat</groupId>
      <artifactId>jackson-dataformat-xml</artifactId>
      <version>2.5.4</version>
   </dependency>
   <dependency>
      <groupId>com.fasterxml.jackson.jaxrs</groupId>
      <artifactId>jackson-jaxrs-json-provider</artifactId>
      <version>2.5.4</version>
   </dependency>
   <dependency>
      <groupId>com.fasterxml.jackson.dataformat</groupId>
      <artifactId>jackson-dataformat-yaml</artifactId>
      <version>2.5.4</version>
   </dependency>
   <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>2.5.4</version>
   </dependency>
   <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.5.4</version>
   </dependency>
   <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>2.5.4</version>
   </dependency>
   <dependency>
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-joda</artifactId>
      <version>2.5.4</version>
   </dependency>
   <dependency>
      <groupId>com.fasterxml.jackson.jaxrs</groupId>
      <artifactId>jackson-jaxrs-base</artifactId>
      <version>2.5.4</version>
   </dependency>
</dependencies>

Thx a lot for the workaround @StevenChoo!!

Try snapshot, we've updated the jackson version there.

I am trying to use this plugin:
https://github.com/gigaSproule/swagger-gradle-plugin

And I am seeing this error. Anyone know a clever way to work around it? Seems like the trick is getting the plugin to use the correct version of Jackson?

@StevenChoo looks like the problem is related to the method been overloaded and it can't pick one of them.

@fehguy --

Try snapshot, we've updated the jackson version there.

i did this 2.0.8 and same failure still exists. what was fixed in snapshot ?

Was this page helpful?
0 / 5 - 0 ratings