Java Code Examples for com.fasterxml.jackson.databind.JavaType#findSuperType()
The following examples show how to use
com.fasterxml.jackson.databind.JavaType#findSuperType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeFactory.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Method similar to {@link #constructSpecializedType}, but that creates a * less-specific type of given type. Usually this is as simple as simply * finding super-type with type erasure of <code>superClass</code>, but * there may be need for some additional work-arounds. * * @param superClass * * @since 2.7 */ public JavaType constructGeneralizedType(JavaType baseType, Class<?> superClass) { // simple optimization to avoid costly introspection if type-erased type does NOT differ final Class<?> rawBase = baseType.getRawClass(); if (rawBase == superClass) { return baseType; } JavaType superType = baseType.findSuperType(superClass); if (superType == null) { // Most likely, caller did not verify sub/super-type relationship if (!superClass.isAssignableFrom(rawBase)) { throw new IllegalArgumentException(String.format( "Class %s not a super-type of %s", superClass.getName(), baseType)); } // 01-Nov-2015, tatu: Should never happen, but ch throw new IllegalArgumentException(String.format( "Internal error: class %s not included as super-type for %s", superClass.getName(), baseType)); } return superType; }
Example 2
Source File: StdConverter.java From lams with GNU General Public License v2.0 | 5 votes |
protected JavaType _findConverterType(TypeFactory tf) { JavaType thisType = tf.constructType(getClass()); JavaType convType = thisType.findSuperType(Converter.class); if (convType == null || convType.containedTypeCount() < 2) { throw new IllegalStateException("Cannot find OUT type parameter for Converter of type "+getClass().getName()); } return convType; }
Example 3
Source File: TypeFactory.java From lams with GNU General Public License v2.0 | 5 votes |
private TypeBindings _bindingsForSubtype(JavaType baseType, int typeParamCount, Class<?> subclass) { PlaceholderForType[] placeholders = new PlaceholderForType[typeParamCount]; for (int i = 0; i < typeParamCount; ++i) { placeholders[i] = new PlaceholderForType(i); } TypeBindings b = TypeBindings.create(subclass, placeholders); // First: pseudo-resolve to get placeholders in place: JavaType tmpSub = _fromClass(null, subclass, b); // Then find super-type JavaType baseWithPlaceholders = tmpSub.findSuperType(baseType.getRawClass()); if (baseWithPlaceholders == null) { // should be found but... throw new IllegalArgumentException(String.format( "Internal error: unable to locate supertype (%s) from resolved subtype %s", baseType.getRawClass().getName(), subclass.getName())); } // and traverse type hierarchies to both verify and to resolve placeholders String error = _resolveTypePlaceholders(baseType, baseWithPlaceholders); if (error != null) { throw new IllegalArgumentException("Failed to specialize base type "+baseType.toCanonical()+" as " +subclass.getName()+", problem: "+error); } final JavaType[] typeParams = new JavaType[typeParamCount]; for (int i = 0; i < typeParamCount; ++i) { JavaType t = placeholders[i].actualType(); // 18-Oct-2017, tatu: Looks like sometimes we have incomplete bindings (even if not // common, it is possible if subtype is type-erased class with added type // variable -- see test(s) with "bogus" type(s)). if (t == null) { t = unknownType(); } typeParams[i] = t; } return TypeBindings.create(subclass, typeParams); }
Example 4
Source File: BatfishThirdPartySerializers.java From batfish with Apache License 2.0 | 5 votes |
@Override public @Nullable JsonSerializer<?> findSerializer( SerializationConfig config, JavaType type, BeanDescription beanDesc) { if (RangeSet.class.isAssignableFrom(type.getRawClass())) { return new RangeSetSerializer(type.findSuperType(RangeSet.class)); } return null; }
Example 5
Source File: JavaUtilCollectionsDeserializers.java From lams with GNU General Public License v2.0 | 4 votes |
static JavaUtilCollectionsConverter converter(int kind, JavaType concreteType, Class<?> rawSuper) { return new JavaUtilCollectionsConverter(kind, concreteType.findSuperType(rawSuper)); }
Example 6
Source File: TypeFactory.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Method that is to figure out actual type parameters that given * class binds to generic types defined by given (generic) * interface or class. * This could mean, for example, trying to figure out * key and value types for Map implementations. * * @param type Sub-type (leaf type) that implements <code>expType</code> */ public JavaType[] findTypeParameters(JavaType type, Class<?> expType) { JavaType match = type.findSuperType(expType); if (match == null) { return NO_TYPES; } return match.getBindings().typeParameterArray(); }