Example usage for com.fasterxml.jackson.dataformat.xml XmlMapper reader

List of usage examples for com.fasterxml.jackson.dataformat.xml XmlMapper reader

Introduction

In this page you can find the example usage for com.fasterxml.jackson.dataformat.xml XmlMapper reader.

Prototype

public ObjectReader reader(DeserializationFeature feature) 

Source Link

Document

Factory method for constructing ObjectReader with specified feature enabled (compared to settings that this mapper instance has).

Usage

From source file:info.donsun.cache.filecache.FileCacheManager.java

/**
 * Parse cache config file//from   w w  w . j  a  v a 2s.  c  o m
 * 
 * @param resourceAsStream
 * @return
 */
private static void parseConfigFile(InputStream resourceAsStream) {
    try {

        XmlMapper mapper = new XmlMapper();

        fileCacheConfig = mapper.reader(FileCacheConfig.class).readValue(resourceAsStream);
        String defaultDir = fileCacheConfig.getDefaultDir();
        Long defaultExpireTime = fileCacheConfig.getDefaultExpireTime();

        List<CacheConfig> cacheConfigs = fileCacheConfig.getCaches();
        if (cacheConfigs != null && cacheConfigs.size() > 0) {
            for (CacheConfig cache : cacheConfigs) {
                Assert.notNull(cache.getName(), "Cache name must not be null.");

                if (StringUtils.isBlank(cache.getDir())) {
                    cache.setDir(defaultDir);
                }
                if (cache.getExpireTime() == null) {
                    cache.setExpireTime(defaultExpireTime);
                }
                caches.put(cache.getName(), cache);
            }
        }
    } catch (JsonProcessingException e) {
        LOG.error("Parse cache config file exception.", e);
    } catch (IOException e) {
        LOG.error("Reade cache config file exception.", e);
    } catch (IllegalArgumentException e) {
        LOG.error("Illegal argument of cache name." + e.getMessage(), e);
    }
}