use of com.fasterxml.jackson.databind.type.CollectionType in project camel by apache.
the class JacksonXMLDataFormat method unmarshal.
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
// is there a header with the unmarshal type?
Class<?> clazz = unmarshalType;
String type = null;
if (allowUnmarshallType) {
type = exchange.getIn().getHeader(JacksonXMLConstants.UNMARSHAL_TYPE, String.class);
}
if (type == null && isAllowJmsType()) {
type = exchange.getIn().getHeader("JMSType", String.class);
}
if (type != null) {
clazz = exchange.getContext().getClassResolver().resolveMandatoryClass(type);
}
if (collectionType != null) {
CollectionType collType = xmlMapper.getTypeFactory().constructCollectionType(collectionType, clazz);
return this.xmlMapper.readValue(stream, collType);
} else {
return this.xmlMapper.readValue(stream, clazz);
}
}
use of com.fasterxml.jackson.databind.type.CollectionType in project camel by apache.
the class JacksonDataFormat method unmarshal.
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
// is there a header with the unmarshal type?
Class<?> clazz = unmarshalType;
String type = null;
if (allowUnmarshallType) {
type = exchange.getIn().getHeader(JacksonConstants.UNMARSHAL_TYPE, String.class);
}
if (type == null && isAllowJmsType()) {
type = exchange.getIn().getHeader("JMSType", String.class);
}
if (type != null) {
clazz = exchange.getContext().getClassResolver().resolveMandatoryClass(type);
}
if (collectionType != null) {
CollectionType collType = objectMapper.getTypeFactory().constructCollectionType(collectionType, clazz);
return this.objectMapper.readValue(stream, collType);
} else {
return this.objectMapper.readValue(stream, clazz);
}
}
use of com.fasterxml.jackson.databind.type.CollectionType in project hadoop by apache.
the class SwiftNativeFileSystemStore method listDirectory.
/**
* List a directory.
* This is O(n) for the number of objects in this path.
*
*
*
* @param path working path
* @param listDeep ask for all the data
* @param newest ask for the newest data
* @return Collection of file statuses
* @throws IOException IO problems
* @throws FileNotFoundException if the path does not exist
*/
private List<FileStatus> listDirectory(SwiftObjectPath path, boolean listDeep, boolean newest) throws IOException {
final byte[] bytes;
final ArrayList<FileStatus> files = new ArrayList<FileStatus>();
final Path correctSwiftPath = getCorrectSwiftPath(path);
try {
bytes = swiftRestClient.listDeepObjectsInDirectory(path, listDeep);
} catch (FileNotFoundException e) {
if (LOG.isDebugEnabled()) {
LOG.debug("" + "File/Directory not found " + path);
}
if (SwiftUtils.isRootDir(path)) {
return Collections.emptyList();
} else {
throw e;
}
} catch (SwiftInvalidResponseException e) {
//bad HTTP error code
if (e.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
//this can come back on a root list if the container is empty
if (SwiftUtils.isRootDir(path)) {
return Collections.emptyList();
} else {
//NO_CONTENT returned on something other than the root directory;
//see if it is there, and convert to empty list or not found
//depending on whether the entry exists.
FileStatus stat = getObjectMetadata(correctSwiftPath, newest);
if (stat.isDirectory()) {
//it's an empty directory. state that
return Collections.emptyList();
} else {
//it's a file -return that as the status
files.add(stat);
return files;
}
}
} else {
//a different status code: rethrow immediately
throw e;
}
}
final CollectionType collectionType = JSONUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, SwiftObjectFileStatus.class);
final List<SwiftObjectFileStatus> fileStatusList = JSONUtil.toObject(new String(bytes, Charset.forName("UTF-8")), collectionType);
//in this case swift will return empty array
if (fileStatusList.isEmpty()) {
SwiftFileStatus objectMetadata = getObjectMetadata(correctSwiftPath, newest);
if (objectMetadata.isFile()) {
files.add(objectMetadata);
}
return files;
}
for (SwiftObjectFileStatus status : fileStatusList) {
if (status.getName() != null) {
files.add(new SwiftFileStatus(status.getBytes(), status.getBytes() == 0, 1, getBlocksize(), status.getLast_modified().getTime(), getCorrectSwiftPath(new Path(status.getName()))));
}
}
return files;
}
use of com.fasterxml.jackson.databind.type.CollectionType in project moco by dreamhead.
the class CollectionReader method read.
public <T> ImmutableList<T> read(final InputStream is, final Class<T> elementClass) {
try {
CollectionType type = factory.constructCollectionType(List.class, elementClass);
List<T> sessionSettings = mapper.readValue(is, type);
return copyOf(sessionSettings);
} catch (UnrecognizedPropertyException e) {
logger.info("Unrecognized field: {}", e.getMessage());
throw new RuntimeException(format("Unrecognized field [ %s ], please check!", e.getPropertyName()));
} catch (JsonMappingException e) {
logger.info("{} {}", e.getMessage(), e.getPathReference());
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
closeQuietly(is);
}
}
use of com.fasterxml.jackson.databind.type.CollectionType in project jackson-databind by FasterXML.
the class TestTypeResolution method testListViaTypeRef.
public void testListViaTypeRef() {
TypeFactory tf = TypeFactory.defaultInstance();
JavaType t = tf.constructType(new TypeReference<MyLongList<Integer>>() {
});
CollectionType type = (CollectionType) t;
assertSame(MyLongList.class, type.getRawClass());
assertEquals(tf.constructType(Long.class), type.getContentType());
}
Aggregations