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:com.monarchapis.driver.configuration.YamlConfiguration.java

/**
 * Returns a Jackson object mapper for reading YAML-formatted input.
 * //  w w  w  .j  av  a2  s  .c o  m
 * @return the object mapper.
 */
protected ObjectMapper getObjectMapper() {
    return new ObjectMapper(new YAMLFactory());
}

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

@Test
public void flattenSomething() throws Exception {
    URL testDocUrl = Resources.getResource(FlattenerTest.class, "flatten-test.yaml");
    JsonNode node = new ObjectMapper(new YAMLFactory()).readTree(testDocUrl);
    Dictionary<String, ?> dict = JsonNodeFlattener.flatten(node);
    assertEquals("blue", dict.get("color"));
    assertEquals("arms", dict.get("limbs[0]"));
    assertEquals("legs", dict.get("limbs[1]"));
    assertEquals(1.0, (Double) dict.get("ingredients.stuffing.thickness"), 0.001);
    assertEquals("a", dict.get("ingredients.topping[0]"));
    assertEquals("dog", dict.get("ingredients.topping[2].cat"));
}

From source file:com.virtlink.commons.configuration2.jackson.YamlConfigurationTests.java

@Override
protected JacksonConfiguration create(final Map<String, Object> properties) throws ConfigurationException {
    return new JacksonConfiguration(new YAMLFactory()) {
    };/* w w w  .  ja  v a2  s .  co  m*/
}

From source file:com.chiralBehaviors.autoconfigure.debug.TemplateDebuggerTest.java

@Test
public void testDebugger() throws Exception {

    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    InputStream yaml = getClass().getResourceAsStream("/yaml/templateDebugger.yml");
    TemplateDebugger debugger = mapper.readValue(yaml, TemplateDebugger.class);
    assertNotNull(debugger);//from   w  w  w.  ja v  a  2s  .  c o m
    String rendered = debugger.render();
    assertNotNull(rendered);
    InputStream gold = getClass().getResourceAsStream("/configurations/templateDebugger.rendered");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Utils.copy(gold, baos);
    String expected = baos.toString();
    assertEquals(expected, rendered);
}

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

@Test
public void unflattenSomething() throws Exception {
    URL testDocUrl = Resources.getResource(FlattenerTest.class, "flatten-test.yaml");
    JsonNode node = new ObjectMapper(new YAMLFactory()).readTree(testDocUrl);
    Dictionary<String, ?> dict = JsonNodeFlattener.flatten(node);
    JsonNode roundTrip = JsonNodeFlattener.unflatten(dict);
    assertEquals(node, roundTrip);/*  w ww  .  java  2 s .c  om*/
}

From source file:org.excalibur.jackson.databind.JsonYamlObjectMapper.java

public JsonYamlObjectMapper() {
    super(new YAMLFactory());

    this.configure(SerializationFeature.INDENT_OUTPUT, true);
    this.registerModule(new JaxbAnnotationModule());
}

From source file:com.amazonaws.scala.ProjectGenerator.java

/**
 * @param baseDir the base directory of the project
 *///from   ww w . j  a v a2 s . c  o  m
public ProjectGenerator(File baseDir) {
    this(baseDir, new Freemarker(), new ObjectMapper(new YAMLFactory()));
}

From source file:com.ysheng.auth.frontend.configuration.ConfigurationParser.java

/**
 * Parses the given configuration file and returns a configuration object.
 *
 * @param configurationFileName The name of the configuration file.
 * @return A configuration object.//from  w  w w. j  a  v a2 s. c o  m
 * @throws IOException The IO error that contains detail information.
 * @throws ConfigurationException The configuration error that contains detail information.
 */
public static ApiConfiguration parse(String configurationFileName) throws IOException, ConfigurationException {
    if (StringUtils.isBlank(configurationFileName)) {
        throw new IllegalArgumentException("Configuration file cannot be blank");
    }

    ObjectMapper objectMapper = null;
    if (configurationFileName.endsWith("yml") || configurationFileName.endsWith("yaml")) {
        objectMapper = Jackson.newObjectMapper(new YAMLFactory());
    } else if (configurationFileName.endsWith("json")) {
        objectMapper = Jackson.newObjectMapper(new JsonFactory());
    } else {
        throw new IllegalArgumentException("Unrecognized configuration file type");
    }

    ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class).configure()
            .addValidatedValueHandler(new OptionalValidatedValueUnwrapper()).buildValidatorFactory();

    final ConfigurationFactory<ApiConfiguration> configurationFactory = new DefaultConfigurationFactoryFactory<ApiConfiguration>()
            .create(ApiConfiguration.class, validatorFactory.getValidator(), objectMapper, "dw");

    final File file = new File(configurationFileName);
    if (!file.exists()) {
        throw new FileNotFoundException("Configuration file " + configurationFileName + " not found");
    }

    return configurationFactory.build(file);
}

From source file:com.hpcloud.util.config.ConfigurationFactory.java

private ConfigurationFactory(Class<T> configType) {
    this.configType = configType;
    this.mapper = new ObjectMapper(new YAMLFactory());
    this.mapper.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}

From source file:io.fabric8.maven.rt.ReadYaml.java

public BoosterYaml readYaml(String boosterUrl) throws IOException {

    //Lets convert the string boosterUrl to URl format.
    URL url = new URL(boosterUrl);

    //Create a temp file to read the data from URL
    File file = File.createTempFile("booster", ".yaml");

    //Read the data from URl and copy it to File
    FileUtils.copyURLToFile(url, file);//ww  w  .  jav a  2s.  c  o m

    //Lets convert the file Bosster Yaml object and return BoosterYaml Object
    final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    return mapper.readValue(file, BoosterYaml.class);
}