|
4 | 4 |
|
5 | 5 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
6 | 6 | import com.fasterxml.jackson.databind.DatabindContext;
|
| 7 | +import com.fasterxml.jackson.databind.DeserializationConfig; |
| 8 | +import com.fasterxml.jackson.databind.DeserializationFeature; |
7 | 9 | import com.fasterxml.jackson.databind.JavaType;
|
| 10 | +import com.fasterxml.jackson.databind.cfg.MapperConfig; |
8 | 11 | import com.fasterxml.jackson.databind.type.TypeFactory;
|
9 | 12 | import com.fasterxml.jackson.databind.util.ClassUtil;
|
10 | 13 |
|
@@ -40,33 +43,44 @@ public String idFromValueAndType(Object value, Class<?> type) {
|
40 | 43 | @Deprecated // since 2.3
|
41 | 44 | @Override
|
42 | 45 | public JavaType typeFromId(String id) {
|
43 |
| - return _typeFromId(id, _typeFactory); |
| 46 | + return _typeFromId(id, null); |
44 | 47 | }
|
45 | 48 |
|
46 | 49 | @Override
|
47 | 50 | public JavaType typeFromId(DatabindContext context, String id) {
|
48 |
| - return _typeFromId(id, context.getTypeFactory()); |
| 51 | + return _typeFromId(id, context); |
49 | 52 | }
|
50 | 53 |
|
51 |
| - protected JavaType _typeFromId(String id, TypeFactory typeFactory) |
| 54 | + protected JavaType _typeFromId(String id, DatabindContext ctxt) |
52 | 55 | {
|
53 | 56 | /* 30-Jan-2010, tatu: Most ids are basic class names; so let's first
|
54 | 57 | * check if any generics info is added; and only then ask factory
|
55 | 58 | * to do translation when necessary
|
56 | 59 | */
|
| 60 | + TypeFactory tf = (ctxt == null) ? _typeFactory : ctxt.getTypeFactory(); |
57 | 61 | if (id.indexOf('<') > 0) {
|
58 |
| - JavaType t = typeFactory.constructFromCanonical(id); |
| 62 | + JavaType t = tf.constructFromCanonical(id); |
59 | 63 | // note: may want to try combining with specialization (esp for EnumMap)?
|
60 | 64 | return t;
|
61 | 65 | }
|
| 66 | + Class<?> cls; |
62 | 67 | try {
|
63 |
| - Class<?> cls = typeFactory.findClass(id); |
64 |
| - return typeFactory.constructSpecializedType(_baseType, cls); |
| 68 | + cls = tf.findClass(id); |
65 | 69 | } catch (ClassNotFoundException e) {
|
| 70 | + // 24-May-2016, tatu: Ok, this is supremely ugly, from multiple persepctives. |
| 71 | + // But fixes [databind#1098], so has to do for now. |
| 72 | + MapperConfig<?> cfg = ctxt.getConfig(); |
| 73 | + if (cfg instanceof DeserializationConfig) { |
| 74 | + DeserializationConfig dc = (DeserializationConfig) cfg; |
| 75 | + if (!dc.isEnabled(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE)) { |
| 76 | + return null; |
| 77 | + } |
| 78 | + } |
66 | 79 | throw new IllegalArgumentException("Invalid type id '"+id+"' (for id type 'Id.class'): no such class found");
|
67 | 80 | } catch (Exception e) {
|
68 | 81 | throw new IllegalArgumentException("Invalid type id '"+id+"' (for id type 'Id.class'): "+e.getMessage(), e);
|
69 | 82 | }
|
| 83 | + return tf.constructSpecializedType(_baseType, cls); |
70 | 84 | }
|
71 | 85 |
|
72 | 86 | /*
|
|
0 commit comments