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());
}
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;
}
Aggregations