No serializer found for class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory...
問題描述
mybatis配置懶載入導致RestController或responsebody返回物件Jackson解析失敗。
關鍵資訊:
No serializer found for class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl and no properties discovered to create BeanSerializer
com.fasterxml.jackson.databind.exc.InvalidDefinitionException
此物件中有其他類物件的屬性!!!
(因為我發現簡單類物件,即類中沒有其他類的物件做為屬性,則用RestController方法返回一切正常)
今天在做springboot專案時,使用mybatis查詢結果用RestController中的方法返回時,遇到 jackson 解析失敗的問題,上網查了方才知道是懶載入的問題,是說在進行實體類代理過程中會新增一個handler的屬性,故導致解析失敗.
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: java.util.ArrayList[0]->cyt.springboot.csms.model.Contract_$$_jvst497_6["handler"])
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1277) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:400) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:71) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:33) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:728) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:755) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:178) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:145) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:107) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:480) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:400) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.ObjectWriter$Prefetch.serialize(ObjectWriter.java:1512) ~[jackson-databind-2.11.3.jar:2.11.3]
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:1006) ~[jackson-databind-2.11.3.jar:2.11.3]
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:345) ~[spring-web-5.3.1.jar:5.3.1]
at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:104) ~[spring-web-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:277) ~[spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:181) ~[spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:78) ~[spring-web-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:124) ~[spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:893) ~[spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:807) ~[spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1061) ~[spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:961) ~[spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.1.jar:5.3.1]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.3.1.jar:5.3.1]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:626) ~[tomcat-embed-core-9.0.39.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.1.jar:5.3.1]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.39.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
。。。。。。
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.39.jar:9.0.39]
at java.base/java.lang.Thread.run(Thread.java:835) ~[na:na]
解決辦法
在實體類前,即你返回需要jackson解析的類,前面新增註解,讓Jackson序列化時忽略handler屬性
@JsonIgnoreProperties(value = "handler")
public class Contract {
private Integer contractId;
private Salesman salesman;
private Client client;
。。。。。。
}
相關文章
- ***報錯Class 'Redis' not found in(原創)Redis
- 使用URLClassLoader報錯not class found exceptionException
- Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for clASTXMLException
- Lumen 報錯 : Class 'League\Flysystem\Adapter\Local' not foundAPT
- Eclipse 啟動專案錯誤:class not foundEclipse
- [Symfony\Component\Debug\Exception\FatalThrowableError] Class 'LaravelLocalization' not foundExceptionErrorLaravel
- kattle Driver class 'oracle.jdbc.driver.OracleDriver' could not be foundOracleJDBC
- Symfony\Component\Debug\Exception\FatalThrowableError Class 'Lcobucci\JWT\Builder' not foundExceptionErrorJWTUI
- ntpq無法查詢同步資訊,顯示The specified class was not found
- JAVA SSH與Class 'org.apache.commons.dbcp.BasicDataSource' not foundJavaApache
- thinkphp ventor引入第三方類庫 class not foundPHP
- JNI開發:Class android.content.Context could not be foundAndroidContext
- 序列化器-Serializer LL
- Ubuntu 20.04 安裝 php-xml 模組(報錯:Class 'DOMDocument' not found )UbuntuPHPXML
- CDH5之Found class jline.Terminal, but interface was expectedH5
- Yii2.0 初識 RESTful SerializerREST
- Django REST Framework中的Serializer relationsDjangoRESTFramework
- linux 報錯 jpype._jexception.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class not foundLinuxExceptionAIJava
- [分享]關於新版本 Composer 會導致 Class not found 的問題
- [WARNING] warning: Class com.google.protobuf.Descriptors not found - continuing with a stub.GoUI
- Laravel 6 ignition 解決 Class 'xxx' not found 載入緩慢問題Laravel
- 案例2問答機器人報TypeError: Class com.hankcs.hanlp.HanLP is not found機器人ErrorHanLP
- Django(45)drf序列化類的使用(Serializer)Django
- 編寫自定義 Laravel 擴充套件包測試用例,phpunit 錯誤提示 “class not found”Laravel套件PHP
- springboot啟動時報異常Class not found so assuming code is running on a pre-Java 9 JVMSpring BootJavaJVM
- drf serializer 字首 get 是什麼? 如何傳遞引數?
- iOS[super class]和[self class]iOS
- composer安裝完成輸入命令報錯:Fatal error: Class ‘Phar‘ not found in C:\\ProgramData\\ComposerSetup\\bin\\compoError
- Typescript的interface、class和abstract classTypeScript
- springboot 引入第三方jar 防在resource路徑下 釋出伺服器提示 class not foundSpring BootJAR伺服器
- self::class和static::class的區別
- 螞蟻金服通訊框架SOFABolt解析 |序列化機制(Serializer)框架
- 螞蟻金服通訊框架SOFABolt解析|序列化機制(Serializer)框架
- SAP 電商雲 Spartacus UI 實現的 ngrx-router-store.js 的 serializerUIJS
- pip: command not found
- The requested URL was not found on the serverServer
- HttpServlet was not found on the JavaHTTPServletJava
- dart class overviewDartView