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;
。。。。。。
}
相關文章
- Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for clASTXMLException
- 使用URLClassLoader報錯not class found exceptionException
- Eclipse 啟動專案錯誤:class not foundEclipse
- Lumen 報錯 : Class 'League\Flysystem\Adapter\Local' not foundAPT
- Symfony\Component\Debug\Exception\FatalThrowableError Class 'Lcobucci\JWT\Builder' not foundExceptionErrorJWTUI
- [WARNING] warning: Class com.google.protobuf.Descriptors not found - continuing with a stub.GoUI
- ntpq無法查詢同步資訊,顯示The specified class was not found
- linux 報錯 jpype._jexception.RuntimeExceptionPyRaisable: java.lang.RuntimeException: Class not foundLinuxExceptionAIJava
- drf Serializer基本使用
- Laravel 6 ignition 解決 Class 'xxx' not found 載入緩慢問題Laravel
- Ubuntu 20.04 安裝 php-xml 模組(報錯:Class 'DOMDocument' not found )UbuntuPHPXML
- [分享]關於新版本 Composer 會導致 Class not found 的問題
- 案例2問答機器人報TypeError: Class com.hankcs.hanlp.HanLP is not found機器人ErrorHanLP
- 序列化器-Serializer LL
- Django REST Framework中的Serializer relationsDjangoRESTFramework
- Yii2.0 初識 RESTful SerializerREST
- drf-序列化器serializer
- springboot啟動時報異常Class not found so assuming code is running on a pre-Java 9 JVMSpring BootJavaJVM
- 編寫自定義 Laravel 擴充套件包測試用例,phpunit 錯誤提示 “class not found”Laravel套件PHP
- composer安裝完成輸入命令報錯:Fatal error: Class ‘Phar‘ not found in C:\\ProgramData\\ComposerSetup\\bin\\compoError
- Django(45)drf序列化類的使用(Serializer)Django
- -bash: id: command not found -bash: tty: command not found
- springboot 引入第三方jar 防在resource路徑下 釋出伺服器提示 class not foundSpring BootJAR伺服器
- kubeadm not found
- iOS[super class]和[self class]iOS
- class
- Typescript的interface、class和abstract classTypeScript
- nodemon: command not found
- pip: command not found
- found an invalid color
- self::class和static::class的區別
- drf serializer 字首 get 是什麼? 如何傳遞引數?
- SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/module/flAIJAR
- 28、Static Nested Class 和 Inner Class的不同。
- zsh:command not found: xxx
- mac mysql: command not foundMacMySql
- Android:Unexpected lock protocol found in lock file. Expected 3, found 0.AndroidProtocol
- dart class overviewDartView