Ignore super class methods / Classloader issue
See original GitHub issueUse case: POJO that extends a 3rd party base class. The base class contains a method whose return type is not available to the ClassLoader.
This seems related to: https://github.com/FasterXML/jackson-databind/pull/785/files and https://github.com/FasterXML/jackson-databind/issues/861
It doesn’t look like it is possible to ignore methods/super class methods, only fields using the AnnotationIntrospector
.
Example using Realm (https://github.com/realm/realm-java):
public class Foo extends RealmObject {
private String bar;
public void setBar(String bar) {
this.bar = bar;
}
public String getBar() {
return bar;
}
}
The problematic method is asObservable()
in RealmObject
that returns an rx.Observable
. RxJava is an optional dependency, so rx.Observable
might not be available to the ClassLoader: https://github.com/realm/realm-java/blob/master/realm/realm-library/src/main/java/io/realm/RealmObject.java#L278-Lundefined
The stack trace from Jackson looks something like this:
java.lang.NoClassDefFoundError: rx.Observable
at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
at java.lang.Class.getDexCacheType(Class.java:479)
at java.lang.reflect.ArtMethod.getDexCacheType(ArtMethod.java:191)
at java.lang.reflect.ArtMethod.getReturnType(ArtMethod.java:145)
at java.lang.reflect.Method.getReturnType(Method.java:184)
at java.lang.Class.getDeclaredMethods(Class.java:771)
at com.fasterxml.jackson.databind.introspect.AnnotatedClass._findClassMethods(AnnotatedClass.java:1046)
at com.fasterxml.jackson.databind.introspect.AnnotatedClass._addMemberMethods(AnnotatedClass.java:602)
at com.fasterxml.jackson.databind.introspect.AnnotatedClass.resolveMemberMethods(AnnotatedClass.java:431)
at com.fasterxml.jackson.databind.introspect.AnnotatedClass.memberMethods(AnnotatedClass.java:253)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addMethods(POJOPropertiesCollector.java:477)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:284)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getPropertyMap(POJOPropertiesCollector.java:248)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getProperties(POJOPropertiesCollector.java:155)
at com.fasterxml.jackson.databind.introspect.BasicBeanDescription._properties(BasicBeanDescription.java:142)
at com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findProperties(BasicBeanDescription.java:217)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._findCreatorsFromProperties(BasicDeserializerFactory.java:333)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._constructDefaultValueInstantiator(BasicDeserializerFactory.java:315)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findValueInstantiator(BasicDeserializerFactory.java:254)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:222)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:142)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:403)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:352)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:461)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:3838)
at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3703)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2005)
at co.moonmonkeylabs.realmsearchview.example.MainActivity.loadBlogData(MainActivity.java:75)
Right now the only fix seems to be to create a dummy rx.Observable
class that is empty, but maybe I am missing some configuration?
Issue Analytics
- State:
- Created 8 years ago
- Reactions:5
- Comments:8 (2 by maintainers)
Top GitHub Comments
Just defining a dummy class as recommended isn’t enough anymore, now I also need the OnSubscribe interface like this:
This is making me very nervous, would love a proper fix.
@rogerioit Feel free to go ahead and figure out potential solution if you have itch here.
No one has proposed valid solution here yet, or, the usual starting point, unit test to reproduce the issue. Without one fixes are difficult to verify. This is not a bug to fix, per se – if system tries to load a class that refers to another class not found in classpath, it is quite natural that problems occur. It would be nice to have a way to handle this gracefully but it is not clear how this should be approached. Asking for someone to solve this will not get you very far.