question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Javassist proxies cause marshaling frameworks (like Jackson) to fail

See original GitHub issue

It looks like there was a change for 3.3.0 that causes marshaling frameworks like Jackson to fail to marshall objects that MyBatis creates that contain proxies for lazy loading to throw exceptions.

Here is the stack trace I am getting from Jackson:

java.lang.RuntimeException: 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: com.inversoft.cleanspeak.domain.system.User_$$_jvst80c_2["applications"]->java.util.HashSet[0]->com.inversoft.cleanspeak.domain.system.Application_$$_jvst80c_4["moderationConfiguration"]->com.inversoft.cleanspeak.domain.system.ModerationConfiguration_$$_jvst80c_5["handler"])
    at com.inversoft.json.ToString.toString(ToString.java:58)
    at com.inversoft.cleanspeak.domain.system.User.toString(User.java:208)
    at com.inversoft.cleanspeak.domain.system.User_$$_jvst80c_2._d15toString(User_$$_jvst80c_2.java)
    at org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory$EnhancedResultObjectProxyImpl.invoke(JavassistProxyFactory.java:161)
    at com.inversoft.cleanspeak.domain.system.User_$$_jvst80c_2.toString(User_$$_jvst80c_2.java)
    at java.lang.String.valueOf(String.java:2994)
    at java.lang.StringBuilder.append(StringBuilder.java:131)
    at com.inversoft.cleanspeak.api.service.user.DefaultUserServiceTest.search(DefaultUserServiceTest.java:178)
Caused by: 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: com.inversoft.cleanspeak.domain.system.User_$$_jvst80c_2["applications"]->java.util.HashSet[0]->com.inversoft.cleanspeak.domain.system.Application_$$_jvst80c_4["moderationConfiguration"]->com.inversoft.cleanspeak.domain.system.ModerationConfiguration_$$_jvst80c_5["handler"])
    at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:59)
    at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:26)
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:505)
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:639)
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152)
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:505)
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:639)
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152)
    at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:117)
    at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:23)
    at com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:183)
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:505)
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:639)
    at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152)
    at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:114)
    at com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:2866)
    at com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:2323)
    at com.inversoft.json.ToString.toString(ToString.java:56)
    ... 36 more
... Removed 29 stack frames

I’ve tested with 3.2.7 and this doesn’t occur. I can probably tweak my Jackson configuration to prevent this stack trace, but it would be nice to figure out what MyBatis and Javassist are generating that is causing the issue and fix that.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:2
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
harawatacommented, Jan 13, 2017

@wuwen5 Thank you for the test case! Adding @JsonIgnoreProperties({"handler"}) to the User class worked for me as well.

I think we should solve the problem in mybatis.

From what I understand, ‘handler’ is an internal property added and used by Javassist and the exception is thrown because Jackson does not know how to process this property. So, to me, it seems like a developer’s responsibility to tell Jackson how to do it because MyBatis is not aware how Jackson or any other marshaling frameworks do their task.

Having said that, I am still open to the idea of adding a low impact workaround in MyBatis if someone knows one. =)

0reactions
thiamteckcommented, Aug 15, 2019

@harawata , yes the addMixin from @kazuki43zoo work, and I just realize my suggestion was not suitable as it required mybatis to have dependency with jackson.

btw, just an add on, the MethodHandler for the interface shall be org.apache.ibatis.javassist.util.proxy.MethodHandler

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strange Jackson exception being thrown when serializing ...
EDIT: I discovered that getHander() and other get*() methods exist on the proxy object. GRR!! Is there any way I can tell Jackson...
Read more >
to avoid exception, disable serializationfeature ... - Polarys
Mybatis-3: Javassist proxies cause marshaling frameworks (like Jackson) to fail. @Bean public ObjectMapper objectMapper () { return new ...
Read more >
Java Bug System - OpenJDK
JVM crash in javassist.util.proxy. ... Seems to be a similar issue. ACTUAL - # # A fatal error has been detected by the...
Read more >
Chapter 3. Class Loading and Modules Red Hat JBoss ...
Dependencies: org.javassist, org.hibernate services. To scan a beans.xml file and make its resulting beans available to the application, the meta-inf ...
Read more >
Fix list for IBM WebSphere Application Server V8.5
PH35855, WebSphere control region failed with ABEND 0C4 in com/ibm/ws390/xmem/proxy/XMemProxyCRCppUtilities.queueInboundRequest. Java SDK.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found