Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot serialize object from mybatis and it has a field lazy-loaded #4681

Closed
1 task done
formingform opened this issue Aug 28, 2024 · 4 comments
Closed
1 task done

Comments

@formingform
Copy link

formingform commented Aug 28, 2024

Search before asking

  • 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

Reproduction

@formingform formingform added the to-evaluate Issue that has been received but not yet evaluated label Aug 28, 2024
@yawkat
Copy link
Member

yawkat commented Aug 28, 2024

Not sure what you want us to do, here

@pjfanning
Copy link
Member

We do not generally accept issues where many libs are used. Reproducible cases should generally use only Jackson libs.
I believe this should be reported to the myBatis community or on stackoverflow.com.

@cowtowncoder cowtowncoder removed the to-evaluate Issue that has been received but not yet evaluated label Aug 29, 2024
@cowtowncoder
Copy link
Member

Yes, "exotic" types by 3rd party libraries/frameworks tend to require special supported, provided often as Jackson datatype modules: for Hibernate, there is https://github.com/FasterXML/jackson-datatype-hibernate/ .

Such libraries would ideally be created and maintained by library/framework maintainers. But we sometimes accept contributions if users want to write implementations.
That requires someone with myBatis and Jackson knowledge.

In this case it is very likely that such contribution (PR) would be needed. Or possibly someone sharing way they have used Jackson configuration and/or custom (de)serializers.

@cowtowncoder
Copy link
Member

Nothing we can do in jackson-databind: would require dedicated datatype module most likely. Will close: anyone can work on implementing and contributed such module; if so, can file an issue somewhere else; f.ex start a Discussion at

https://github.com/FasterXML/jackson/discussions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants