Example usage for com.fasterxml.jackson.dataformat.yaml YAMLFactory YAMLFactory

List of usage examples for com.fasterxml.jackson.dataformat.yaml YAMLFactory YAMLFactory

Introduction

In this page you can find the example usage for com.fasterxml.jackson.dataformat.yaml YAMLFactory YAMLFactory.

Prototype

public YAMLFactory() 

Source Link

Document

Default constructor used to create factory instances.

Usage

From source file:uk.co.flax.biosolr.ontology.config.loaders.YamlConfigurationLoader.java

public YamlConfigurationLoader(String configFile) {
    this.configFile = configFile;
    this.yamlFactory = new YAMLFactory();
    this.mapper = new ObjectMapper();
}

From source file:com.github.born2snipe.maven.log.config.ConfigSerializer.java

private Config loadUrl(URL url) {
    try {//  w w  w.ja va 2  s.c om
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        return mapper.readValue(url, Config.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.seedstack.coffig.provider.JacksonProvider.java

public JacksonProvider() {
    YAMLFactory yamlFactory = new YAMLFactory();
    jacksonMapper = new ObjectMapper(yamlFactory);
}

From source file:org.elasticsoftware.elasticactors.runtime.DefaultConfigurationTest.java

@Test
public void testLoadDefaultConfig() throws IOException {
    File configFile = ResourceUtils.getFile("classpath:ea-default.yaml");
    // get the yaml resource

    // yaml mapper
    ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
    DefaultConfiguration configuration = objectMapper.readValue(new FileInputStream(configFile),
            DefaultConfiguration.class);

    assertEquals(configuration.getName(), "default");
    assertEquals(configuration.getNumberOfShards(), 8);
    assertNotNull(configuration.getRemoteConfigurations());
    assertFalse(configuration.getRemoteConfigurations().isEmpty());
    assertEquals(configuration.getRemoteConfigurations().size(), 2);
    assertEquals(configuration.getRemoteConfigurations().get(0).getClusterName(), "test2.elasticsoftware.org");
    assertEquals(configuration.getRemoteConfigurations().get(1).getClusterName(), "test3.elasticsoftware.org");
    //assertEquals(configuration.getProperty(HttpService.class, "listenPort", Integer.class, 9090),new Integer(8080));
}

From source file:io.scigraph.owlapi.loader.OwlLoadConfigurationLoader.java

public OwlLoadConfiguration loadConfig() throws JsonParseException, JsonMappingException, IOException {

    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    OwlLoadConfiguration config = mapper.readValue(configurationFile, OwlLoadConfiguration.class);

    CurieUtil curieUtil = new CurieUtil(config.getGraphConfiguration().getCuries());

    // resolve categories
    Map<String, String> resolvedCategories = new HashMap<String, String>();
    for (Map.Entry<String, String> entry : config.getCategories().entrySet()) {
        Optional<String> iriOpt = curieUtil.getIri(entry.getKey());
        resolvedCategories.put(iriOpt.or(entry.getKey()), entry.getValue());
    }/*  www  . ja v a 2 s  . c o m*/
    config.setCategories(resolvedCategories);

    // resolve MappedProperties
    List<MappedProperty> resolvedMappedProperties = new ArrayList<MappedProperty>();
    for (MappedProperty mappedProperty : config.getMappedProperties()) {
        MappedProperty resolvedMappedProperty = new MappedProperty(mappedProperty.name);
        List<String> resolvedProperties = new ArrayList<String>();
        for (String property : mappedProperty.getProperties()) {
            resolvedProperties.add(curieUtil.getIri(property).or(property));
        }
        resolvedMappedProperty.setProperties(resolvedProperties);
        resolvedMappedProperties.add(resolvedMappedProperty);
    }
    config.setMappedProperties(resolvedMappedProperties);

    return config;
}

From source file:com.jaeksoft.opensearchserver.ServerConfiguration.java

/**
 * Load the configuration file.//from  w w  w. j  a v  a  2 s.  c om
 * 
 * @param file
 * @return an instance of ServerConfiguration
 * @throws JsonParseException
 * @throws JsonMappingException
 * @throws IOException
 */
static ServerConfiguration getNewInstance(File file)
        throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    return mapper.readValue(file, ServerConfiguration.class);
}

From source file:com.basistech.yca.UnflattenTest.java

@Test
public void objectInArray() throws Exception {
    Hashtable<String, Object> ht = new Hashtable<>();
    ht.put("a[0].cat", "dog");
    ht.put("a[0].dog", "cat");
    JsonNode roundTrip = JsonNodeFlattener.unflatten(ht);
    JsonNode ref = new ObjectMapper(new YAMLFactory()).readTree("a: [ { cat: dog, dog: cat } ]");
    assertEquals(ref, roundTrip);/*  w  w  w  .j  av  a  2s .  com*/
}

From source file:com.jeqo.samples.eventsource.infra.kafka.KafkaConsumerProvider.java

public void init(@Observes @Initialized(ApplicationScoped.class) Object init) {
    try {//from w  w w . j av  a  2  s. co m
        config = new ObjectMapper(new YAMLFactory()).readValue(
                this.getClass().getClassLoader().getResourceAsStream("kafka-consumer.yml"),
                KafkaConsumerConfig.class);

        Properties props = new Properties();
        props.put("zookeeper.connect", "localhost:2181");
        props.put("group.id", config.getGroupId());
        props.put("zookeeper.session.timeout.ms", "413");
        props.put("zookeeper.sync.time.ms", "203");
        props.put("auto.commit.interval.ms", "1000");

        ConsumerConfig cf = new ConsumerConfig(props);
        consumer = Consumer.createJavaConsumerConnector(cf);
    } catch (IOException ex) {
        LOGGER.log(Level.SEVERE, "Error KafkaConsumerProvider init", ex);
    }
}

From source file:com.cognifide.qa.bb.utils.YamlReader.java

/**
 * Reads yaml configuration file under given path and returns structure defined in {@link TypeReference}.
 *
 * @param path path to yaml configuration file.
 * @param type type which will be used to construct result.
 * @param <T>  type of the mapped object
 * @return YAML file mapped to an object defined by provided TypeReference
 *//*from   w  ww . ja  v a  2s  .  c om*/
public static <T> T read(String path, Class<T> type) {
    try {
        return new ObjectMapper(new YAMLFactory()).readValue(readFile(path), type);
    } catch (IOException e) {
        LOG.error(COULD_NOT_PARSE_YAML_FILE, path, e);
        throw new IllegalStateException(YAML_FILE_COULD_NOT_BE_READ, e);
    }
}

From source file:io.scigraph.owlapi.loader.OwlLoadConfigurationLoaderTest.java

@Before
public void setup() throws URISyntaxException, JsonParseException, JsonMappingException, IOException {
    URL url = this.getClass().getResource("/pizzaExample.yaml");
    File pizzaFile = new File(url.getFile());

    assertThat(pizzaFile.exists(), is(true));
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    rawConfig = mapper.readValue(pizzaFile, OwlLoadConfiguration.class);

    OwlLoadConfigurationLoader owlLoadConfigurationLoader = new OwlLoadConfigurationLoader(pizzaFile);
    loaderConfig = owlLoadConfigurationLoader.loadConfig();
    curieUtil = new CurieUtil(rawConfig.getGraphConfiguration().getCuries());
}