All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.duracloud.snapshot.service.impl.PropertiesSerializer Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
/*
 * The contents of this file are subject to the license and copyright
 * detailed in the LICENSE and NOTICE files at the root of the source
 * tree and available online at
 *
 *     http://duracloud.org/license/
 */
package org.duracloud.snapshot.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

/**
 * @author Daniel Bernstein Date: Jul 31, 2014
 */
public class PropertiesSerializer {
    private static ObjectMapper mapper = new ObjectMapper();
    private static TypeReference> mapTypeRef =
        new TypeReference>() {
        };

    private PropertiesSerializer() {
        // Ensures no instances are made of this class, as there are only static members.
    }

    public static String serialize(Map props) {
        try {
            return mapper.writeValueAsString(props);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public static Map deserialize(String src) {
        HashMap props;

        try {
            props =
                new ObjectMapper().readValue(src, mapTypeRef);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }

        return props;

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy