Search in sources :

Example 6 with CollectionType

use of com.fasterxml.jackson.databind.type.CollectionType in project jackson-databind by FasterXML.

the class TestTypeResolution method testListViaClass.

public void testListViaClass() {
    TypeFactory tf = TypeFactory.defaultInstance();
    JavaType t = tf.constructType(LongList.class);
    JavaType type = (CollectionType) t;
    assertSame(LongList.class, type.getRawClass());
    assertEquals(tf.constructType(Long.class), type.getContentType());
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) CollectionType(com.fasterxml.jackson.databind.type.CollectionType) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory)

Example 7 with CollectionType

use of com.fasterxml.jackson.databind.type.CollectionType in project EnrichmentMapApp by BaderLab.

the class PropertiesJsonDeserializer method readValue.

public static Object readValue(final String key, final String input, final ObjectMapper mapper, final AbstractChart<?> chart) {
    Object value = null;
    final Class<?> type = chart.getSettingType(key);
    if (type != null) {
        final TypeFactory typeFactory = mapper.getTypeFactory();
        try {
            if (type == Array.class) {
                final Class<?> elementType = chart.getSettingElementType(key);
                if (elementType != null) {
                    final ArrayType arrType = typeFactory.constructArrayType(elementType);
                    if (mapper.canDeserialize(arrType))
                        value = mapper.readValue(input, arrType);
                }
            } else if (List.class.isAssignableFrom(type)) {
                final Class<?> elementType = chart.getSettingElementType(key);
                if (elementType != null) {
                    final CollectionType collType = typeFactory.constructCollectionType(List.class, elementType);
                    if (mapper.canDeserialize(collType))
                        value = mapper.readValue(input, collType);
                }
            } else {
                final JavaType simpleType = typeFactory.constructSimpleType(type, new JavaType[] {});
                if (mapper.canDeserialize(simpleType))
                    value = mapper.readValue(input, simpleType);
            }
        } catch (Exception e) {
            logger.error("Cannot parse JSON field " + key, e);
        }
    }
    return value;
}
Also used : ArrayType(com.fasterxml.jackson.databind.type.ArrayType) JavaType(com.fasterxml.jackson.databind.JavaType) CollectionType(com.fasterxml.jackson.databind.type.CollectionType) List(java.util.List) TypeFactory(com.fasterxml.jackson.databind.type.TypeFactory) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

CollectionType (com.fasterxml.jackson.databind.type.CollectionType)7 JavaType (com.fasterxml.jackson.databind.JavaType)3 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)3 IOException (java.io.IOException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 UnrecognizedPropertyException (com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException)1 ArrayType (com.fasterxml.jackson.databind.type.ArrayType)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 Path (org.apache.hadoop.fs.Path)1 SwiftInvalidResponseException (org.apache.hadoop.fs.swift.exceptions.SwiftInvalidResponseException)1 SwiftObjectPath (org.apache.hadoop.fs.swift.util.SwiftObjectPath)1