Package com.marcusilgner.ghcity.helpers

Source Code of com.marcusilgner.ghcity.helpers.Json

package com.marcusilgner.ghcity.helpers;

import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;

import java.io.IOException;
import java.io.InputStream;

public class Json {
    public static <T> T fromJson(Object o, Class<T> clazz) {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, true);
        mapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);

        T result = null;
        try {
            if(o instanceof InputStream)
                result = mapper.readValue((InputStream) o, clazz);
            if(o instanceof String)
                result = mapper.readValue((String) o, clazz);
        } catch (IOException e) {
            // pass
        }

        return result;
    }
}
TOP

Related Classes of com.marcusilgner.ghcity.helpers.Json

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.