protected JavaType _typeFromId(String id, DatabindContext ctxt) throws IOException { JavaType t = ctxt.resolveSubType(_baseType, id); if (t == null) { if (ctxt instanceof DeserializationContext) { // First: we may have problem handlers that can deal with it? return ((DeserializationContext) ctxt).handleUnknownTypeId(_baseType, id, this, "no such class found"); } // ... meaning that we really should never get here. } return t; }
/** * Helper method called when given type id cannot be resolved into * concrete deserializer either directly (using given {@link TypeIdResolver}), * or using default type. * Default implementation simply throws a {@link com.fasterxml.jackson.databind.JsonMappingException} to * indicate the problem; sub-classes may choose * * @return If it is possible to resolve type id into a {@link JsonDeserializer} * should return that deserializer; otherwise throw an exception to indicate * the problem. * * @since 2.8 */ protected JavaType _handleUnknownTypeId(DeserializationContext ctxt, String typeId) throws IOException { String extraDesc = _idResolver.getDescForKnownTypeIds(); if (extraDesc == null) { extraDesc = "type ids are not statically known"; } else { extraDesc = "known type ids = " + extraDesc; } if (_property != null) { extraDesc = String.format("%s (for POJO property '%s')", extraDesc, _property.getName()); } return ctxt.handleUnknownTypeId(_baseType, typeId, _idResolver, extraDesc); }
protected JavaType _typeFromId(String id, DatabindContext ctxt) throws IOException { JavaType t = ctxt.resolveSubType(_baseType, id); if (t == null) { if (ctxt instanceof DeserializationContext) { // First: we may have problem handlers that can deal with it? return ((DeserializationContext) ctxt).handleUnknownTypeId(_baseType, id, this, "no such class found"); } // ... meaning that we really should never get here. } return t; }
@Override public JavaType typeFromId(DatabindContext context, String id) throws IOException { try { Class<?> type = Class.forName(id); return context.constructType(type); } catch (ClassNotFoundException e) { if(!(context instanceof DeserializationContext)) { throw new RuntimeException(e); } //see magic from ClassNameIdResolver._typeFromId() return ((DeserializationContext) context).handleUnknownTypeId(_baseType, id, this, "Class '" + id + "' not found."); } }
/** * Helper method called when given type id can not be resolved into * concrete deserializer either directly (using given {@link TypeIdResolver}), * or using default type. * Default implementation simply throws a {@link com.fasterxml.jackson.databind.JsonMappingException} to * indicate the problem; sub-classes may choose * * @return If it is possible to resolve type id into a {@link JsonDeserializer} * should return that deserializer; otherwise throw an exception to indicate * the problem. * * @since 2.8 */ protected JavaType _handleUnknownTypeId(DeserializationContext ctxt, String typeId, TypeIdResolver idResolver, JavaType baseType) throws IOException { String extraDesc = idResolver.getDescForKnownTypeIds(); if (extraDesc == null) { extraDesc = "known type ids are not statically known"; } else { extraDesc = "known type ids = " + extraDesc; } return ctxt.handleUnknownTypeId(_baseType, typeId, idResolver, extraDesc); } }
/** * Helper method called when given type id cannot be resolved into * concrete deserializer either directly (using given {@link TypeIdResolver}), * or using default type. * Default implementation simply throws a {@link com.fasterxml.jackson.databind.JsonMappingException} to * indicate the problem; sub-classes may choose * * @return If it is possible to resolve type id into a {@link JsonDeserializer} * should return that deserializer; otherwise throw an exception to indicate * the problem. * * @since 2.8 */ protected JavaType _handleUnknownTypeId(DeserializationContext ctxt, String typeId) throws IOException { String extraDesc = _idResolver.getDescForKnownTypeIds(); if (extraDesc == null) { extraDesc = "type ids are not statically known"; } else { extraDesc = "known type ids = " + extraDesc; } if (_property != null) { extraDesc = String.format("%s (for POJO property '%s')", extraDesc, _property.getName()); } return ctxt.handleUnknownTypeId(_baseType, typeId, _idResolver, extraDesc); }
protected JavaType _typeFromId(String id, DatabindContext ctxt) throws IOException { /* 30-Jan-2010, tatu: Most ids are basic class names; so let's first * check if any generics info is added; and only then ask factory * to do translation when necessary */ TypeFactory tf = ctxt.getTypeFactory(); if (id.indexOf('<') > 0) { // note: may want to try combining with specialization (esp for EnumMap)? return tf.constructFromCanonical(id); } Class<?> cls; try { cls = tf.findClass(id); } catch (ClassNotFoundException e) { // 24-May-2016, tatu: Ok, this is pretty ugly, but we should always get // DeserializationContext, just playing it safe if (ctxt instanceof DeserializationContext) { DeserializationContext dctxt = (DeserializationContext) ctxt; // First: we may have problem handlers that can deal with it? return dctxt.handleUnknownTypeId(_baseType, id, this, "no such class found"); } // ... meaning that we really should never get here. return null; } catch (Exception e) { throw new IllegalArgumentException("Invalid type id '"+id+"' (for id type 'Id.class'): "+e.getMessage(), e); } return tf.constructSpecializedType(_baseType, cls); }