|
2 | 2 |
|
3 | 3 | import javax.persistence.Transient;
|
4 | 4 |
|
5 |
| -import org.hibernate.bytecode.internal.javassist.FieldHandler; |
6 |
| - |
7 | 5 | import com.fasterxml.jackson.core.Version;
|
8 | 6 | import com.fasterxml.jackson.databind.AnnotationIntrospector;
|
9 | 7 | import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
|
|
17 | 15 | public class HibernateAnnotationIntrospector extends AnnotationIntrospector
|
18 | 16 | {
|
19 | 17 | private static final long serialVersionUID = 1L;
|
20 |
| - |
| 18 | + |
21 | 19 | /**
|
22 | 20 | * Whether we should check for existence of @Transient or not.
|
23 | 21 | * Default value is 'true'.
|
@@ -78,10 +76,37 @@ public Boolean isIgnorableType(AnnotatedClass ac)
|
78 | 76 | * of `FieldHandled`. Not sure if it works without test (alas, none provided),
|
79 | 77 | * but will try our best -- problem is, if it'
|
80 | 78 | */
|
81 |
| - // ... could we avoid direct class reference? |
82 |
| - if (FieldHandler.class.isAssignableFrom(ac.getAnnotated())) { |
83 |
| - return Boolean.TRUE; |
| 79 | + // 11-Feb-2016, tatu: As per [datatype-hibernate#86] must use indirection. Sigh. |
| 80 | + Class<?> handlerClass = FieldHandlerChecker.instance.getHandlerClass(); |
| 81 | + if (handlerClass != null) { |
| 82 | + if (handlerClass.isAssignableFrom(ac.getAnnotated())) { |
| 83 | + return Boolean.TRUE; |
| 84 | + } |
84 | 85 | }
|
85 | 86 | return null;
|
86 | 87 | }
|
| 88 | + |
| 89 | + /** |
| 90 | + * Helper class used to encapsulate detection of <code>FieldHandler</code>; class |
| 91 | + * that was part of Hibernate from 4.0 until 5.0, but removed from 5.1. |
| 92 | + */ |
| 93 | + final static class FieldHandlerChecker { |
| 94 | + private final static String FIELD_HANDLER_INTERFACE = "org.hibernate.bytecode.internal.javassist.FieldHandler"; |
| 95 | + |
| 96 | + private final Class<?> _handlerClass; |
| 97 | + |
| 98 | + public final static FieldHandlerChecker instance = new FieldHandlerChecker(); |
| 99 | + |
| 100 | + public FieldHandlerChecker() { |
| 101 | + Class<?> cls = null; |
| 102 | + try { |
| 103 | + cls = Class.forName(FIELD_HANDLER_INTERFACE); |
| 104 | + } catch (Throwable t) { } |
| 105 | + _handlerClass = cls; |
| 106 | + } |
| 107 | + |
| 108 | + public Class<?> getHandlerClass() { |
| 109 | + return _handlerClass; |
| 110 | + } |
| 111 | + } |
87 | 112 | }
|
0 commit comments