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.wso2telco.core.pcrservice.util.YamlReader.java

/**
 * Gets the configuration.//from  ww  w .jav a  2 s .c  o m
 *
 * @return the configuration
 */
public static ConfigDTO getConfiguration() {

    File file = new File(DEVICE_MGT_CONFIG_PATH);
    ConfigDTO configPojo = new ConfigDTO();

    final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); // jackson databind

    try {
        configPojo = mapper.readValue(file, ConfigDTO.class);
    } catch (JsonParseException e) {
        log.error("Yaml Parsing Error", e);
    } catch (JsonMappingException e) {
        log.error("Yaml Mapping Error", e);
    } catch (IOException e) {
        log.error("Yaml File Error", e);
    }

    return configPojo;
}

From source file:com.chiralBehaviors.groo.configuration.ChakaalConfiguration.java

public static ChakaalConfiguration fromYaml(InputStream yaml)
        throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    mapper.registerModule(new DiscoveryModule());
    return mapper.readValue(yaml, ChakaalConfiguration.class);
}

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 typeReference type reference 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
 *//* www  .  j a  va 2 s .c  o  m*/
public static <T> T read(String path, TypeReference typeReference) {
    try {
        return new ObjectMapper(new YAMLFactory()).readValue(readFile(path), typeReference);
    } 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:com.trusolve.ant.filters.JsonToYamlFilter.java

public static Reader readDocument(Reader in) throws JsonProcessingException, IOException {
    ObjectMapper jsonIn = new ObjectMapper();
    JsonNode jn = jsonIn.readTree(in);/*w  w  w.  j  ava2  s  . c om*/

    YAMLFactory yf = new YAMLFactory();
    StringWriter sw = new StringWriter();

    yf.createGenerator(sw).setCodec(new ObjectMapper(yf)).writeObject(jn);

    return new StringReader(sw.toString());
}

From source file:org.mayocat.theme.ThemeDefinitionTest.java

@Before
public void setUp() throws Exception {
    mapper = new ObjectMapper(new YAMLFactory());
}

From source file:com.chiralBehaviors.slp.hive.hardtack.configuration.PushConfiguration.java

public static PushConfiguration fromYaml(InputStream yaml)
        throws JsonParseException, JsonMappingException, IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    //mapper.registerModule(new EngineModule());
    return mapper.readValue(yaml, PushConfiguration.class);
}

From source file:sonata.kernel.vimadaptor.wrapper.openstack.javastackclient.JavaStackUtils.java

public static String convertYamlToJson(String yamlToConvert) throws IOException {
    ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
    Object obj = yamlReader.readValue(yamlToConvert, Object.class);

    ObjectMapper jsonWriter = new ObjectMapper();
    return jsonWriter.writeValueAsString(obj);
}

From source file:org.smartdeveloperhub.vocabulary.config.ConfigurationFactory.java

private static YAMLFactory yamlFactory() {
    return new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)
            .disable(YAMLGenerator.Feature.CANONICAL_OUTPUT).enable(YAMLGenerator.Feature.SPLIT_LINES)
            .enable(YAMLGenerator.Feature.MINIMIZE_QUOTES).enable(YAMLGenerator.Feature.USE_NATIVE_OBJECT_ID)
            .enable(YAMLGenerator.Feature.USE_NATIVE_TYPE_ID);
}

From source file:yamlparse.parser.ApplicationsInparser.java

private void parseIn(String yamlString) {
    try {//ww w  . ja v a 2 s.  c  o  m
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        this.parseResults = mapper.readValue(yamlString, yamlparse.datatypes.applications.Applications.class);
    } catch (IOException ex) {
        Logger.getLogger(AbstractParseManager.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:io.anserini.doc.GenerateRegressionDocsTest.java

@Test
public void main() throws Exception {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    URL resource = GenerateRegressionDocsTest.class.getResource("/regression/all.yaml");
    DataModel data = mapper.readValue(Paths.get(resource.toURI()).toFile(), DataModel.class);
    //System.out.println(ReflectionToStringBuilder.toString(data, ToStringStyle.MULTI_LINE_STYLE));

    for (String collection : data.getCollections().keySet()) {
        Map<String, String> valuesMap = new HashMap<>();
        valuesMap.put("index_cmds", data.generateIndexingCommand(collection));
        valuesMap.put("ranking_cmds", data.generateRankingCommand(collection));
        valuesMap.put("eval_cmds", data.generateEvalCommand(collection));
        valuesMap.put("effectiveness", data.generateEffectiveness(collection));
        StrSubstitutor sub = new StrSubstitutor(valuesMap);
        URL template = GenerateRegressionDocsTest.class
                .getResource(String.format("/docgen/templates/%s.template", collection));
        Scanner scanner = new Scanner(Paths.get(template.toURI()).toFile(), "UTF-8");
        String text = scanner.useDelimiter("\\A").next();
        scanner.close();//from  ww  w .  jav a2 s . c o  m
        String resolvedString = sub.replace(text);

        FileUtils.writeStringToFile(new File(String.format("docs/experiments-%s.md", collection)),
                resolvedString, "UTF-8");
    }
}