0

I added library with this dependency

        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>

then when I try to create pojo class Idea told me that it can't find class but class exist java.lang.ClassNotFoundException: org.codehaus.jackson.annotate.JsonUnwrapped

@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.addHeader("Content-Type", "application/json; charset=utf-8");
    StringBuilder builder = new StringBuilder();
    String a = null;
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(req.getInputStream(), "UTF-8"))){
        while ((a = reader.readLine())!=null){
            builder.append(a);
        }
    }
    ObjectMapper objectMapper = new ObjectMapper();
    UserPojo pojo = objectMapper.readValue(builder.toString(),UserPojo.class);
   }

Example picture:

I have this library in classpath. And I try to use another version of jackson. When I use version 2.+ I have another crazy error Idea can't find class ObjectMapper only in this class.

On this picture i have class (ObjectMapper) not found error:

On this picture I DON'T have error:

but this two class in one package. How it's possible and How it's fix?

Add pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>PetClinic</groupId>
    <artifactId>cpw</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>Clinic Pet Web</name>
    <url>http://maven.apache.org</url>

    <dependencies>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.3.5.Final</version>
        </dependency>
        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.1-901-1.jdbc4</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-core-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.13</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
        </dependency>
        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.1</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-utils</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>PetClinic</groupId>
            <artifactId>se</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.10.19</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <finalName>PetClinicWeb</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.4.201502262128</version>
                <configuration>
                    <destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
                    <dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
                </configuration>
                <executions>
                    <execution>
                        <id>jacoco-initialize</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
2
  • could you also post your pom, it's possible you have some conflicting libraries and the one you expect to have JsonUnwrapped is not included after conflict resolved Commented Oct 9, 2018 at 7:51
  • @GiorgosDev I'm add pom to main post Commented Oct 9, 2018 at 8:16

3 Answers 3

1

Try to use com.fasterxml jackson-annotations and jackson-core packages, and in general better to use 2+ version. Seems like the class JsonUnwrapped you have is from version 1 which is in org.codehaus.jackson package, while some other library uses version 2 (which has different package - com.fasterxml.jackson). Try to replace your jackson dependencies with following:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.7.8</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.7.8</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.7.8</version>
</dependency>

As for missing ObjectMapper most likely you did not update your import statement. So switch to version 2 and replace all imports of codehouse jackson with fasterxml. It is important to have same version of all jackson libraries.

Also if your project has any parent project, check if jackson is imported there and what version it has. It might have elder version, in this case change your libraries version respectively, or just remove the version so it will be inherited from parent.

See https://dzone.com/articles/jackson-dependency-issue-in-spring-boot-with-maven for more details

Sign up to request clarification or add additional context in comments.

1 Comment

I'm make it. Look down. And you forget about databind. ObjectMapper located in databind
0

I'm add jackson version 2.7.8

<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.7.8</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.7.8</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.7.8</version>
    </dependency>

Than I make clean and package in Maven Project

But ObjectMapper is not found

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>PetClinic</groupId>
    <artifactId>PetClinicMain</artifactId>
    <version>1.0-SNAPSHOT</version>

    <packaging>pom</packaging>

    <name>Pet Clinic</name>
    <url>http://maven.apache.org</url>

    <modules>
        <module>se</module>
        <module>clinic-pet-web</module>
    </modules>

</project>

8 Comments

try also reimport all maven projects
in your pom I don't see <parent> tag, but you probably have it. It is also possible that it uses different version of Jackson in parent. I am updating my answer with details
@GiorgosDev i don't add parent becouse my main pom don't have any dependency. I'm add main pom in my last answer.
@GiorgosDev I'm update all my project on git github.com/LegeArtis/Web-Pet-Clinic
@GiorgosDev I'm fixed this) I'm add jackson jar files to WEB-INF/lib As I uderstand add dependecy not enough
|
0

I'm fixed this exeption. I'm add jackson jar files to WEB-INF/lib As I uderstand add dependecy not enough. enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.