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

io.snice.networking.examples.Utils Maven / Gradle / Ivy

There is a newer version: 0.0.13
Show newest version
package io.snice.networking.examples;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.snice.networking.config.NetworkInterfaceConfiguration;
import io.snice.networking.config.NetworkInterfaceDeserializer;

import java.io.InputStream;

public class Utils {


    /**
     * Helper method for loading a configuration.
     *
     * @param clazz
     * @param resource
     * @return
     * @throws Exception
     */
    public static  T loadConfiguration(final Class clazz, final String resource) throws Exception {
        final InputStream stream = Utils.class.getResourceAsStream(resource);
        final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        final SimpleModule module = new SimpleModule();
        module.addDeserializer(NetworkInterfaceConfiguration.class, new NetworkInterfaceDeserializer());
        mapper.registerModule(module);
        mapper.registerModule(new JavaTimeModule());
        return mapper.readValue(stream, clazz);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy