From 3858853f649949c8eba9302d1c42d63d017b260f Mon Sep 17 00:00:00 2001 From: Charles Allen Date: Thu, 7 May 2015 12:56:37 -0700 Subject: [PATCH] Add handlings for classes which are available in `Thread.currentThread().getContextClassLoader()` --- .../databind/introspect/AnnotatedClass.java | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotatedClass.java b/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotatedClass.java index fa379b104d..bcc5bb79a4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotatedClass.java +++ b/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotatedClass.java @@ -378,7 +378,30 @@ private void resolveCreators() List creatorMethods = null; // Then static methods which are potential factory methods - for (Method m : _class.getDeclaredMethods()) { + + Method[] classMethods; + try{ + classMethods = _class.getDeclaredMethods(); + }catch(final NoClassDefFoundError ex){ + // One of the methods had a class that was not found in the cls.getClassLoader. + // Maybe the developer was nice and has a different class loader for this context. + final ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if(loader == null){ + // Nope... this is going to end poorly + throw ex; + } + final Class contextClass; + try { + contextClass = loader.loadClass(_class.getName()); + } + catch (ClassNotFoundException e) { + //ex.addSuppressed(e); Not until 1.7 + throw ex; + } + classMethods = contextClass.getDeclaredMethods(); // Cross fingers + } + + for (Method m : classMethods) { if (!Modifier.isStatic(m.getModifiers())) { continue; } @@ -596,9 +619,29 @@ protected void _addMemberMethods(Class cls, AnnotatedMethodMap methods, if (cls == null) { // just so caller need not check when passing super-class return; } - + Method[] classMethods; + try{ + classMethods = cls.getDeclaredMethods(); + }catch(final NoClassDefFoundError ex){ + // One of the methods had a class that was not found in the cls.getClassLoader. + // Maybe the developer was nice and has a different class loader for this context. + final ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (loader == null) { + // Nope... this is going to end poorly + throw ex; + } + final Class contextClass; + try { + contextClass = loader.loadClass(cls.getName()); + } + catch (ClassNotFoundException e) { + //ex.addSuppressed(e); Not until 1.7 + throw ex; + } + classMethods = contextClass.getDeclaredMethods(); // Cross fingers + } // then methods from the class itself - for (Method m : cls.getDeclaredMethods()) { + for (Method m : classMethods) { if (!_isIncludableMemberMethod(m)) { continue; }