Skip to content

Commit 340439a

Browse files
committed
Merge branch '2.4' into 2.5
Conflicts: release-notes/CREDITS release-notes/VERSION src/main/java/com/fasterxml/jackson/databind/introspect/AnnotatedClass.java
2 parents f4ef389 + 7db1f44 commit 340439a

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

release-notes/CREDITS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,8 @@ Andrew Duckett (andrewduckett@github)
245245
* Reported #771: Annotation bundles ignored when added to Mixin
246246
(2.5.4)
247247

248+
Charles Allen:
249+
* Contributed #785: Add handlings for classes which are available in
250+
`Thread.currentThread().getContextClassLoader()`
251+
(2.5.4)
252+

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Project: jackson-databind
1313
(reported by Andrew D)
1414
#774: NPE from SqlDateSerializer as _useTimestamp is not checked for being null
1515
(reported by mrowkow@github)
16+
#785: Add handlings for classes which are available in `Thread.currentThread().getContextClassLoader()`
17+
(contributed by Charles A)
1618
- Fix handling of Enums wrt JSON Schema, when 'toString()' used for serialization
1719

1820
2.5.3 (24-Apr-2015)

src/main/java/com/fasterxml/jackson/databind/introspect/AnnotatedClass.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ private void resolveCreators()
380380
List<AnnotatedMethod> creatorMethods = null;
381381

382382
// Then static methods which are potential factory methods
383-
for (Method m : _class.getDeclaredMethods()) {
383+
for (Method m : _findClassMethods(_class)) {
384384
if (!Modifier.isStatic(m.getModifiers())) {
385385
continue;
386386
}
@@ -411,7 +411,7 @@ private void resolveCreators()
411411
}
412412
_creatorsResolved = true;
413413
}
414-
414+
415415
/**
416416
* Method for resolving member method information: aggregating all non-static methods
417417
* and combining annotations (to implement method-annotation inheritance)
@@ -598,9 +598,8 @@ protected void _addMemberMethods(Class<?> cls, AnnotatedMethodMap methods,
598598
if (cls == null) { // just so caller need not check when passing super-class
599599
return;
600600
}
601-
602601
// then methods from the class itself
603-
for (Method m : cls.getDeclaredMethods()) {
602+
for (Method m : _findClassMethods(cls)) {
604603
if (!_isIncludableMemberMethod(m)) {
605604
continue;
606605
}
@@ -1016,6 +1015,37 @@ private final boolean _isAnnotationBundle(Annotation ann) {
10161015
return (_annotationIntrospector != null) && _annotationIntrospector.isAnnotationBundle(ann);
10171016
}
10181017

1018+
/**
1019+
* Helper method that gets methods declared in given class; usually a simple thing,
1020+
* but sometimes (as per [databind#785]) more complicated, depending on classloader
1021+
* setup.
1022+
*
1023+
* @since 2.4.7
1024+
*/
1025+
protected Method[] _findClassMethods(Class<?> cls)
1026+
{
1027+
try {
1028+
return cls.getDeclaredMethods();
1029+
} catch (final NoClassDefFoundError ex) {
1030+
// One of the methods had a class that was not found in the cls.getClassLoader.
1031+
// Maybe the developer was nice and has a different class loader for this context.
1032+
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
1033+
if(loader == null){
1034+
// Nope... this is going to end poorly
1035+
throw ex;
1036+
}
1037+
final Class<?> contextClass;
1038+
try {
1039+
contextClass = loader.loadClass(cls.getName());
1040+
} catch (ClassNotFoundException e) {
1041+
// !!! TODO: 08-May-2015, tatu: Chain appropriately once we have JDK7 as baseline
1042+
//ex.addSuppressed(e); Not until 1.7
1043+
throw ex;
1044+
}
1045+
return contextClass.getDeclaredMethods(); // Cross fingers
1046+
}
1047+
}
1048+
10191049
/*
10201050
/**********************************************************
10211051
/* Other methods

0 commit comments

Comments
 (0)