jackson-databind
jackson-databind copied to clipboard
Cannot serialize object from mybatis and it has a field lazy-loaded
Search before asking
- [X] I searched in the issues and found nothing similar.
Describe the bug
Jackson 2.13.5 Spring Boot 2.17.x Mybatis 3.5.x JDK 17
Here is my Mybatis map.xml
<resultMap id="BaseResultMap" type="User">
<id property="id" column="id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<collection property="bookNames"
ofType="String"
column="name"
jdbcType="VARCHAR"
select="BookMapper.listBookNamesByOwner" fetchType="lazy"/>
</resultMap>
......
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from user
where id = #{id,jdbcType=INTEGER}
</select>
jackson cannot serialize the result of selectByPrimaryKey because of fetchType="lazy", error message like this:
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)
and if set fetchType=“eager" or remove fetchType="lazy", Jackson works fine.
Version Information
Jackson verison: 2.13.5