JsonMappingException: No serializer found for class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory...

1. Appoint <collection> Labeled select, Lazy loading is possible , and SQL It won't be that complicated , Easy to read

<collection property="articles" column="article_id" fetchType="eager"
ofType="com.jv.dynamic.bean.Article" select="queryArticleById">
</collection>

2. Directly in <collection> Write database fields and in the tag Java Attribute mapping

<collection property="articles" ofType="com.jv.dynamic.bean.Article">
<id property="id" column="article_id"/>
<result property="title" column="title"/>
<result property="content" column="content"/>
<result property="blogId" column="bid"/>
</collection>

3. Appoint <collection> Labeled resultMap attribute , Can improve resultMap The reuse rate of

<collection property="articles" ofType="com.jv.dynamic.bean.Article" resultMap="articleMap">
</collection>
<resultMap type="com.jv.dynamic.bean.Article" id="articleMap">
<id property="id" column="article_id"/>
<result property="title" column="title"/>
<result property="content" column="content"/>
<result property="blogId" column="bid"/>
</resultMap>

I used the first method in the project , The data read out , But in SpringMVC Serialization error when returning

com.fasterxml.jackson.databind.JsonMappingException: 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]->com.jv.dynamic.bean.Blog_$$_jvstd75_0["handler"])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:275)
at com.fasterxml.jackson.databind.SerializerProvider.mappingException(SerializerProvider.java:1109)
at com.fasterxml.jackson.databind.SerializerProvider.reportMappingProblem(SerializerProvider.java:1134)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:69)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:32)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:690)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:155)
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serializeContents(IndexedListSerializer.java:119)
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:79)
at com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer.serialize(IndexedListSerializer.java:18)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:292)
at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3672)
at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:3048)
at com.jv.test.TestBlog.test1(TestBlog.java:46)
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:483)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

I searched a lot on the Internet , Say that this error can be used @JsonIgnore @JsonIgnoreProperties And so on , But try all the solutions I can find , Not yet. ... What should I do , Take your time debug, Step by step, narrow down the scope of errors , Finally, a new ordinary Java For engineering jackson A little , Suddenly found that the printed nested query result has only one row , But the real query result is 6 Yes , If the MyBatis Students who have some understanding may have guessed the reason ... Yes ... The nested query method I chose is delayed loading by default , I set

<collection property="roleList" ofType="com.cloud.base.admin.api.entity.SysRole" fetchType="eager"
select="com.cloud.base.admin.mapper.SysRoleMapper.listRolesByUserId" column="id">
</collection>

Retest , A miracle happened .

So when developing the project , If you want to use the first nested query , Then you need to seriously consider your object , If serialization is not involved , You can boldly use its delayed loading (fetchType="lazy"), Otherwise, it will be loaded at one time (fetchType="eager"


title :JsonMappingException: No serializer found for class org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory...
author : jockming112
Address : http://www.itwetouch.com/articles/2021/09/08/1631091502221.html

Please bring the original link to reprint ,thank
Similar articles

2021-09-15

2021-09-15

2021-09-15