[alibaba/fastjson]1.2.71版本,在JDK1.7下运行JSON.parseObject时,报错java.lang.ClassNotFoundException: java.time.LocalDateTime

2024-05-22 292 views
1

你好: 在1.2.71版本下,使用如下方法测试可以复现。JDK版本1.7. public class DbInfoTest { public static void main(String[] args) throws Exception { String json = "{\"test\":\"test\"}"; Test t = JSON.parseObject(json,Test.class); System.out.println(t.test); } } public class Test { public String test; } 报错信息: Exception in thread "main" java.lang.NoClassDefFoundError: java/time/LocalDateTime at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2595) at java.lang.Class.getConstructor0(Class.java:2895) at java.lang.Class.getConstructor(Class.java:1731) at com.alibaba.fastjson.parser.deserializer.ASMDeserializerFactory.createJavaBeanDeserializer(ASMDeserializerFactory.java:90) at com.alibaba.fastjson.parser.ParserConfig.createJavaBeanDeserializer(ParserConfig.java:1075) at com.alibaba.fastjson.parser.ParserConfig.getDeserializer(ParserConfig.java:882) at com.alibaba.fastjson.parser.ParserConfig.getDeserializer(ParserConfig.java:592) at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:679) at com.alibaba.fastjson.JSON.parseObject(JSON.java:396) at com.alibaba.fastjson.JSON.parseObject(JSON.java:300) at com.alibaba.fastjson.JSON.parseObject(JSON.java:573) at com.rkhd.ienterprise.dbinfo.DbInfoTest.main(DbInfoTest.java:11) Caused by: java.lang.ClassNotFoundException: java.time.LocalDateTime at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) ... 13 more

回答

8

如果注释掉JavaBeanDeserializer的1460行value = TypeUtils.castToLocalDateTime(value, format);则可以正常运行。 else if (format != null && (paramType instanceof Class) && (((Class) paramType).getName().equals("java.time.LocalDateTime"))) { value = TypeUtils.castToLocalDateTime(value, format); }

7

确实有这个bug存在,还是回退到1.2.70