Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialization error when using gson library and swagger-codegen-maven-plugin #20

Open
daniilmatafonov opened this issue Dec 17, 2019 · 0 comments

Comments

@daniilmatafonov
Copy link

daniilmatafonov commented Dec 17, 2019

In my project I use swagger-codegen-maven-plugin 2.4.9 + rest assured 4.1.1 and gson library for serialization. When I added the swagger-coverage in the pom.xml, jackson library was included into the classpath too. When i started to build my project the class model was generated using gson library.

The following error occurred while running the tests:

[ERROR] checkDeposit(com.test.SimpleTest)  Time elapsed: 1.859 s  <<< ERROR!
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: 
Unrecognized field "Result" (class com.test.model.ApiResultIResponseAuth), not marked as ignorable (2 known properties: "error", "result"])
 at [Source: (String)"{"Result":{"AccessToken":"token","Expires"[truncated 296 chars]; line: 1, column: 12] (through reference chain: com.test.model.ApiResultIResponseAuth["Result"])

Workaround:
One of simple workarounds is maven exclusions.
You may just exclude jackson library from classpath for swagger-coverage-rest-assured:

<dependency>
           <groupId>com.github.viclovsky.swagger.coverage</groupId>
           <artifactId>swagger-coverage-rest-assured</artifactId>
           <version>1.1.0</version>
           <exclusions>
               <exclusion>
                   <groupId>com.fasterxml.jackson</groupId>
                   <artifactId>jackson-core</artifactId>
               </exclusion>
               <exclusion>
                   <groupId>com.fasterxml.jackson.core</groupId>
                   <artifactId>jackson-databind</artifactId>
               </exclusion>
               <exclusion>
                   <groupId>com.fasterxml.jackson.core</groupId>
                   <artifactId>jackson-annotations</artifactId>
               </exclusion>
           </exclusions>
</dependency>

Or you may configure RestAssured to use GSON serialization library directly.
This can be done using ObjectMapperConfig.java
https://github.com/rest-assured/rest-assured/blob/master/rest-assured/src/main/java/io/restassured/config/ObjectMapperConfig.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant