Spring boot : org.codehaus.jackson.map.exc.Unrecog

2019-08-27 01:49发布

问题:

I have a spring boot application that execute a reverse Swagger Yaml :

<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
        <execution>
            <id>generate-swagger-java</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${basedir}/src/main/resources/swagger/cview.yaml</inputSpec>
                <apiPackage>client.api</apiPackage>
                <modelPackage>client.model</modelPackage>
                <output>${project.build.directory}/generated-sources</output>
                <language>java</language>
                <configOptions>
                    <dateLibrary>java8</dateLibrary>
                    <library>jersey2</library>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

Running with a main class, it works well

public static void main(final String[] args) {
 SpringApplication.run(SpringBootApp.class, args);
}

But when I run it with SpringBootServletInitializer on WebSphere libertyCore it stucks and gives me those errors when I try to call a web service :

org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "id_entite" (Class client.model.GaEj), not marked as ignorable

Problem with reading the data, class client.model.SearchResultGaEj, ContentType: application/json;charset=UTF-8

the problem is that i dont have any dependency with org.codehaus.jackson.*

I only use com.fasterxml.jackson.datatype

回答1:

By default, WebSphere uses Codehaus Jackson (reference). WebSphere uses two Class-loader modes: Parent first and Parent last. You need to be sure that application uses Jackson from FasterXML not from Codehause. Spring Boot does not have any own managed libraries but WebSphere is an Application Server which provides many already attached libraries so you do not need to provide them with your app.

See:

  1. Catch JsonProcessingException from Jackson in Websphere Liberty
  2. Change Default JSON Provider on WebSphere Application Server
  3. Override Jackson Object Mapper properties on Websphere 8.5.5 using Apache Wink
  4. How to change Jackson version in JAX-RS app (WebSphere Liberty)