发布于 2年前

解决jackson报错:java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ser.std.ToStringSerializerBase

报错信息:

Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ser/std/ToStringSerializerBase
at java.lang.ClassLoader.defineClass1(Native Method) ~[?:1.8.0_202]
at java.lang.ClassLoader.defineClass(ClassLoader.java:763) ~[?:1.8.0_202]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[?:1.8.0_202]
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468) ~[?:1.8.0_202]
at java.net.URLClassLoader.access$100(URLClassLoader.java:74) ~[?:1.8.0_202]
at java.net.URLClassLoader$1.run(URLClassLoader.java:369) ~[?:1.8.0_202]
at java.net.URLClassLoader$1.run(URLClassLoader.java:363) ~[?:1.8.0_202]
at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_202]
.....
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ser.std.ToStringSerializerBase
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[?:1.8.0_202]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_202]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[?:1.8.0_202]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.8.0_202]
at java.lang.ClassLoader.defineClass1(Native Method) ~[?:1.8.0_202]
at java.lang.ClassLoader.defineClass(ClassLoader.java:763) ~[?:1.8.0_202]

可以查看ToStringSerializerBase的APIToStringSerializerBase是jackson2.10新增的类。解决办法使用2.10以上的jackson

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

这是版本不兼容的问题,需要根据项目中所使用的版本选择。

©2020 edoou.com   京ICP备16001874号-3