alibaba / fastjson2

🚄 FASTJSON2 is a Java JSON library with excellent performance.
Apache License 2.0
3.78k stars 495 forks source link

[出现java.lang.NoClassDefFoundError: com/baomidou/mybatisplus/core/conditions/AbstractWrapper$$Lambda$798/831344888] #1424

Closed javaHBZ closed 1 year ago

javaHBZ commented 1 year ago

问题描述

在我将对象转化为字符串的时候出现了这个问题,我用其他的工具包转化是没有问题的

环境信息

请填写以下信息:

重现步骤

如何操作可以重现该问题:

  1. 使用 JSON.toJSONString(Object obj) 方法
  2. 输入 数据
  3. 出现 java.lang.NoClassDefFoundError: com/baomidou/mybatisplus/core/conditions/AbstractWrapper$$Lambda$798/831344888 错误
    public static Object intercept(Invocation invocation) throws Throwable {
        MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
        //请求参数
        Object parameter = null;
        if (1 < invocation.getArgs().length) {
            parameter = invocation.getArgs()[1];
        }
        BoundSql boundSql = mappedStatement.getBoundSql(parameter);
        String sql = boundSql.getSql();
        //执行的sql所在的mapper文件
        String resource = mappedStatement.getResource();
        //执行sql的dao文件的包名+方法名
        String daoMethod = mappedStatement.getId();
        //去除sql文中的换行
        sql = sql.replace("\n", "").replaceAll("\\s+", " ");
        if (SHOWSQL) {
            LOGGER.warn("\n" +
                            "[SQLMonitorPlugin]SQL监控:{}|{}\n" +//方法
                            "执行SQL:\n" +
                            "{}\n" +//SQL
                            "参数:{}", resource, daoMethod,
                    sql, JSON.toJSONString(parameter));
        }
        try {
            long start = System.currentTimeMillis();
            Object e = invocation.proceed();
            long timeTicket = System.currentTimeMillis() - start;
            if (SLOWER < timeTicket) {
                LOGGER.warn("[SQLMonitorInterceptor]SQL监控:{}|{},慢SQL({}/{}ms){},参数:{}",
                        resource, daoMethod, timeTicket, SLOWER, sql, JSON.toJSONString(parameter));
            }
            if (e instanceof Collection) {
                int ct = ((Collection<?>) e).size();
                if (MAXCOUNT < ct) {
                    LOGGER.warn("[SQLMonitorInterceptor]SQL监控:{}|{},大集合({}/{}){},参数:{}",
                            resource, daoMethod, ct, MAXCOUNT, sql, JSON.toJSONString(parameter));
                }
            }
            return e;
        } catch (Exception e) {
            LOGGER.warn("[SQLMonitorPlugin]SQL监控:{}|{},执行出错:{},参数:{}", resource, daoMethod,
                    sql, JSON.toJSONString(parameter), e);
            throw e;
        }
    }

期待的正确结果

成功转化为json字符串

相关日志输出

*java.lang.NoClassDefFoundError: com/baomidou/mybatisplus/core/conditions/AbstractWrapper$$Lambda$798/831344888 at com.alibaba.fastjson2.writer.FieldWriterStringFunc.write(FieldWriterStringFunc.java:41) at com.alibaba.fastjson2.writer.ObjectWriter1.write(ObjectWriter1.java:68) at com.alibaba.fastjson2.writer.ObjectWriterImplList.write(ObjectWriterImplList.java:373) at com.alibaba.fastjson2.writer.OWG_2_5_MergeSegments.write(Unknown Source) at com.alibaba.fastjson2.writer.OWG_1_16_QueryWrapper.write(Unknown Source) at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:548) at com.alibaba.fastjson2.JSON.toJSONString(JSON.java:2334) at org.beite.common.handler.MyBatisSQLMonitorPlugin.intercept(MyBatisSQLMonitorPlugin.java:64) at org.beite.common.handler.SQLMonitorPlugin.beforeQuery(SQLMonitorPlugin.java:35) at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:78) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) at com.sun.proxy.$Proxy102.query(Unknown Source) at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:132) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) at com.sun.proxy.$Proxy102.query(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) at com.sun.proxy.$Proxy80.selectList(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:166) at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:77) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) at com.sun.proxy.$Proxy86.selectList(Unknown Source) at org.beite.service.impl.ArticleTagsServiceImpl.getTagsNames(ArticleTagsServiceImpl.java:57) at org.beite.service.impl.ArticleTagsServiceImpl$$FastClassBySpringCGLIB$$a9f6dd3a.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy.invokeMethod(CglibAopProxy.java:386) at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:85) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:704) at org.beite.service.impl.ArticleTagsServiceImpl$$EnhancerBySpringCGLIB$$2806e68b.getTagsNames() at org.beite.service.impl.ArticleServiceImpl.getArticleById(ArticleServiceImpl.java:129) at org.beite.service.impl.ArticleServiceImpl$$FastClassBySpringCGLIB$$f7fbc213.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) at org.springframework.aop.framework.CglibAopProxy.invokeMethod(CglibAopProxy.java:386) at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:85) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:704) at org.beite.service.impl.ArticleServiceImpl$$EnhancerBySpringCGLIB$$191ae4b6.getArticleById() at org.beite.controller.article.ArticleController.getArticleById(ArticleController.java:47) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) at javax.servlet.http.HttpServlet.service(HttpServlet.java:655) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.beite.common.filter.AuthorizeAttributeFilter.doFilter(AuthorizeAttributeFilter.java:87) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.ClassNotFoundException: com.baomidou.mybatisplus.core.conditions.AbstractWrapper$$Lambda$798.831344888 at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 89 more*

附加信息

image

wenshao commented 1 year ago

这个问题升级到2.0.29应该就好了,你试试看

javaHBZ commented 1 year ago

image image 还是会出现这个问题

wenshao commented 1 year ago

AbstractWrapper这个类的代码能提供下么?

wenshao commented 1 year ago

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.30-SNAPSHOT/ 问题已经修复,请帮忙用2.0.30-SNAPSHOT版本验证,2.0.30版本预计在5月9日前发布

javaHBZ commented 1 year ago

/*

import com.baomidou.mybatisplus.core.conditions.interfaces.Compare; import com.baomidou.mybatisplus.core.conditions.interfaces.Func; import com.baomidou.mybatisplus.core.conditions.interfaces.Join; import com.baomidou.mybatisplus.core.conditions.interfaces.Nested; import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments; import com.baomidou.mybatisplus.core.enums.SqlKeyword; import com.baomidou.mybatisplus.core.enums.SqlLike; import com.baomidou.mybatisplus.core.toolkit.*; import com.baomidou.mybatisplus.core.toolkit.sql.SqlUtils; import com.baomidou.mybatisplus.core.toolkit.sql.StringEscape;

import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiPredicate; import java.util.function.Consumer;

import static com.baomidou.mybatisplus.core.enums.SqlKeyword.*; import static com.baomidou.mybatisplus.core.enums.WrapperKeyword.APPLY; import static com.baomidou.mybatisplus.core.enums.WrapperKeyword.BRACKET; import static java.util.stream.Collectors.joining;

/**

javaHBZ commented 1 year ago

好的 我去试试

javaHBZ commented 1 year ago

出现了新的问题,我用的包的名称是 fastjson2-2.0.30-20230429.115149-8.jar

报错信息

 ### Error querying database.  Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@747910e4, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@747910e4})'
### Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@747910e4, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@747910e4})'
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96) ~[mybatis-spring-2.0.6.jar:2.0.6]
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441) ~[mybatis-spring-2.0.6.jar:2.0.6]
    at com.sun.proxy.$Proxy80.selectList(Unknown Source) ~[na:na]
    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) ~[mybatis-spring-2.0.6.jar:2.0.6]
    at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:166) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
    at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:77) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
    at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
    at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
    at com.sun.proxy.$Proxy82.selectList(Unknown Source) ~[na:na]
    at com.baomidou.mybatisplus.extension.service.IService.list(IService.java:370) ~[mybatis-plus-extension-3.5.2.jar:3.5.2]
    at com.baomidou.mybatisplus.extension.service.IService.list(IService.java:379) ~[mybatis-plus-extension-3.5.2.jar:3.5.2]
    at org.beite.service.impl.ArticleCategoryServiceImpl.listAllCategories(ArticleCategoryServiceImpl.java:27) ~[classes/:na]
    at org.beite.service.impl.ArticleCategoryServiceImpl$$FastClassBySpringCGLIB$$f29cc435.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar:5.3.20]
    at org.springframework.aop.framework.CglibAopProxy.invokeMethod(CglibAopProxy.java:386) ~[spring-aop-5.3.20.jar:5.3.20]
    at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:85) ~[spring-aop-5.3.20.jar:5.3.20]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:704) ~[spring-aop-5.3.20.jar:5.3.20]
    at org.beite.service.impl.ArticleCategoryServiceImpl$$EnhancerBySpringCGLIB$$648b3ea8.listAllCategories(<generated>) ~[classes/:na]
    at org.beite.controller.article.ArticleCategoryController.getAllCategories(ArticleCategoryController.java:29) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) [spring-webmvc-5.3.20.jar:5.3.20]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:655) [tomcat-embed-core-9.0.63.jar:4.0.FR]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.3.20.jar:5.3.20]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) [tomcat-embed-core-9.0.63.jar:4.0.FR]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.beite.common.filter.AuthorizeAttributeFilter.doFilter(AuthorizeAttributeFilter.java:87) [classes/:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.3.20.jar:5.3.20]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) [spring-web-5.3.20.jar:5.3.20]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
wenshao commented 1 year ago

是不是没有把rootCause发出来,错误堆栈中没看到fastjson的。没有rootCause的堆栈,不好诊断问题

javaHBZ commented 1 year ago
nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'
### Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'】

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'
### Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:96) ~[mybatis-spring-2.0.6.jar:2.0.6]
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441) ~[mybatis-spring-2.0.6.jar:2.0.6]
    at com.sun.proxy.$Proxy80.selectList(Unknown Source) ~[na:na]
    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) ~[mybatis-spring-2.0.6.jar:2.0.6]
    at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.executeForMany(MybatisMapperMethod.java:166) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
    at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:77) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
    at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
    at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
    at com.sun.proxy.$Proxy86.selectList(Unknown Source) ~[na:na]
    at com.baomidou.mybatisplus.extension.service.IService.list(IService.java:370) ~[mybatis-plus-extension-3.5.2.jar:3.5.2]
    at com.baomidou.mybatisplus.extension.service.IService.list(IService.java:379) ~[mybatis-plus-extension-3.5.2.jar:3.5.2]
    at org.beite.service.impl.ArticleTagsServiceImpl.listTags(ArticleTagsServiceImpl.java:53) ~[classes/:na]
    at org.beite.service.impl.ArticleTagsServiceImpl$$FastClassBySpringCGLIB$$a9f6dd3a.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar:5.3.20]
    at org.springframework.aop.framework.CglibAopProxy.invokeMethod(CglibAopProxy.java:386) ~[spring-aop-5.3.20.jar:5.3.20]
    at org.springframework.aop.framework.CglibAopProxy.access$000(CglibAopProxy.java:85) ~[spring-aop-5.3.20.jar:5.3.20]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:704) ~[spring-aop-5.3.20.jar:5.3.20]
    at org.beite.service.impl.ArticleTagsServiceImpl$$EnhancerBySpringCGLIB$$f7a8bfb.listTags(<generated>) ~[classes/:na]
    at org.beite.controller.article.ArticleTagsController.getListTags(ArticleTagsController.java:30) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.3.20.jar:5.3.20]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) [spring-webmvc-5.3.20.jar:5.3.20]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:655) [tomcat-embed-core-9.0.63.jar:4.0.FR]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.3.20.jar:5.3.20]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) [tomcat-embed-core-9.0.63.jar:4.0.FR]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.beite.common.filter.AuthorizeAttributeFilter.doFilter(AuthorizeAttributeFilter.java:87) [classes/:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.3.20.jar:5.3.20]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) [spring-web-5.3.20.jar:5.3.20]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.63.jar:9.0.63]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]
Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'
### Cause: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149) ~[mybatis-3.5.6.jar:3.5.6]
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) ~[mybatis-3.5.6.jar:3.5.6]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) ~[mybatis-spring-2.0.6.jar:2.0.6]
    ... 62 common frames omitted
Caused by: com.alibaba.fastjson2.JSONException: JSON#toJSONString cannot serialize 'MyBatisSQLMonitorPlugin.SqlParamWrapper(param={ew=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946, param1=com.baomidou.mybatisplus.core.toolkit.Wrappers$EmptyWrapper@4de45946})'
    at com.alibaba.fastjson2.JSON.toJSONString(JSON.java:2339) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
    at org.beite.common.handler.MyBatisSQLMonitorPlugin.intercept(MyBatisSQLMonitorPlugin.java:81) ~[classes/:na]
    at org.beite.common.handler.SQLMonitorPlugin.beforeQuery(SQLMonitorPlugin.java:42) ~[classes/:na]
    at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:78) ~[mybatis-plus-extension-3.5.2.jar:3.5.2]
    at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.6.jar:3.5.6]
    at com.sun.proxy.$Proxy102.query(Unknown Source) ~[na:na]
    at com.github.pagehelper.PageInterceptor.intercept(PageInterceptor.java:132) ~[pagehelper-5.3.0.jar:na]
    at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61) ~[mybatis-3.5.6.jar:3.5.6]
    at com.sun.proxy.$Proxy102.query(Unknown Source) ~[na:na]
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ~[mybatis-3.5.6.jar:3.5.6]
    ... 68 common frames omitted
Caused by: java.lang.NullPointerException: null
    at com.baomidou.mybatisplus.core.conditions.Wrapper.getTargetSql(Wrapper.java:173) ~[mybatis-plus-core-3.5.2.jar:3.5.2]
    at com.alibaba.fastjson2.writer.FieldWriterStringFunc.write(FieldWriterStringFunc.java:41) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
    at com.alibaba.fastjson2.writer.ObjectWriterAdapter.write(ObjectWriterAdapter.java:303) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
    at com.alibaba.fastjson2.writer.ObjectWriterImplMap.write(ObjectWriterImplMap.java:548) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
    at com.alibaba.fastjson2.writer.FieldWriterObject.write(FieldWriterObject.java:327) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
    at com.alibaba.fastjson2.writer.ObjectWriter1.write(ObjectWriter1.java:68) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
    at com.alibaba.fastjson2.JSON.toJSONString(JSON.java:2334) ~[fastjson2-2.0.30-20230429.115149-8.jar:na]
    ... 77 common frames omitted
wenshao commented 1 year ago

加上JSONWriter.Feature.IgnoreErrorGetter试试看,比如:

JSON.toJSONString(object, JSONWriter.Feature.IgnoreErrorGetter);
wenshao commented 1 year ago

全局配置:

JSON.config(JSONWriter.Feature.IgnoreErrorGetter);

或者更新下快照,看下新版本是否会不加也不报错

做了这个处理: https://github.com/alibaba/fastjson2/commit/8fd9d6de2ab7ca504932ab5231237bd0c47dd347

javaHBZ commented 1 year ago

好的

javaHBZ commented 1 year ago

问题已经解决了,不加也可以,使用的快照版本是 fastjson2-2.0.30-20230429.134008-9.jar

wenshao commented 1 year ago

https://github.com/alibaba/fastjson2/releases/tag/2.0.30 请用新版本