Java Code Examples for com.fasterxml.jackson.databind.JavaType#equals()

The following examples show how to use com.fasterxml.jackson.databind.JavaType#equals() . 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 vote down vote up
/**
 * Method for constructing a {@link CollectionType}.
 *<p>
 * NOTE: type modifiers are NOT called on Collection type itself; but are called
 * for contained types.
 */
public CollectionType constructCollectionType(Class<? extends Collection> collectionClass,
        JavaType elementType)
{
    TypeBindings bindings = TypeBindings.createIfNeeded(collectionClass, elementType);
    CollectionType result = (CollectionType) _fromClass(null, collectionClass, bindings);
    // 17-May-2017, tatu: As per [databind#1415], we better verify bound values if (but only if)
    //    type being resolved was non-generic (i.e.element type was ignored)
    if (bindings.isEmpty() && (elementType != null)) {
        JavaType t = result.findSuperType(Collection.class);
        JavaType realET = t.getContentType();
        if (!realET.equals(elementType)) {
            throw new IllegalArgumentException(String.format(
                    "Non-generic Collection class %s did not resolve to something with element type %s but %s ",
                    ClassUtil.nameOf(collectionClass), elementType, realET));
        }
    }
    return result;
}
 
Example 2
Source File: TypeFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method for constructing a {@link MapType} instance
 *<p>
 * NOTE: type modifiers are NOT called on constructed type itself; but are called
 * for contained types.
 */
public MapType constructMapType(Class<? extends Map> mapClass, JavaType keyType, JavaType valueType) {
    TypeBindings bindings = TypeBindings.createIfNeeded(mapClass, new JavaType[] { keyType, valueType });
    MapType result = (MapType) _fromClass(null, mapClass, bindings);
    // 17-May-2017, tatu: As per [databind#1415], we better verify bound values if (but only if)
    //    type being resolved was non-generic (i.e.element type was ignored)
    if (bindings.isEmpty()) {
        JavaType t = result.findSuperType(Map.class);
        JavaType realKT = t.getKeyType();
        if (!realKT.equals(keyType)) {
            throw new IllegalArgumentException(String.format(
                    "Non-generic Map class %s did not resolve to something with key type %s but %s ",
                    ClassUtil.nameOf(mapClass), keyType, realKT));
        }
        JavaType realVT = t.getContentType();
        if (!realVT.equals(valueType)) {
            throw new IllegalArgumentException(String.format(
                    "Non-generic Map class %s did not resolve to something with value type %s but %s ",
                    ClassUtil.nameOf(mapClass), valueType, realVT));
        }
    }
    return result;
}
 
Example 3
Source File: ReadOnlyClassToSerializerMap.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public boolean matchesTyped(JavaType key) {
    return _isTyped && key.equals(_type);
}
 
Example 4
Source File: ReadOnlyClassToSerializerMap.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public boolean matchesUntyped(JavaType key) {
    return !_isTyped && key.equals(_type);
}