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.mugarov.alfapipe.model.programparse.generators.GeneratorCore.java

public void parseOut() {
    if (this.available != null) {
        try {//from   w  w w.  j  a v  a2  s . c  om
            if (!localFile.exists()) {
                localFile.createNewFile();
            }

            YAMLFactory factory = new YAMLFactory();
            ObjectMapper yamlmap = new ObjectMapper(factory);
            yamlmap.setSerializationInclusion(JsonInclude.Include.NON_NULL);

            FileOutputStream fos = new FileOutputStream(localFile);

            factory.createGenerator(fos).writeObject(this.available);
        } catch (IOException ex) {
            Logger.getLogger(GeneratorCore.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.aerofs.baseline.config.Configuration.java

@SuppressWarnings("unchecked")
public static <C extends Configuration> C loadYAMLConfigurationFromStream(Class<?> derived,
        InputStream configStream) throws IOException {
    ObjectMapper configurationMapper = new ObjectMapper(new YAMLFactory());
    Class<?> configurationTypeClass = Generics.getTypeParameter(derived, Configuration.class);
    return (C) configurationMapper.readValue(configStream, configurationTypeClass);
}

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

/**
 * Reads yaml configuration file under given path in test resources 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
 *//*  w  ww. j  av a2  s.  c om*/
public static <T> T readFromTestResources(String path, TypeReference typeReference) {
    try {
        return new ObjectMapper(new YAMLFactory()).readValue(readFileFromTestResource(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.base2.kagura.core.storage.ReportsProvider.java

/**
 * Loads a report, this does the deserialization, this method can be substituted with another, called by child
 * classes. Once it has deserialized it, it put it into the map.
 * @param result/*from   w w  w. j a  va  2  s .co  m*/
 * @param report
 * @param reportName
 * @return
 */
protected boolean loadReport(ReportsConfig result, InputStream report, String reportName) {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    ReportConfig reportConfig = null;
    try {
        reportConfig = mapper.readValue(report, ReportConfig.class);
    } catch (IOException e) {
        e.printStackTrace();
        errors.add("Error parsing " + reportName + " " + e.getMessage());
        return false;
    }
    reportConfig.setReportId(reportName);
    result.getReports().put(reportName, reportConfig);
    return true;
}

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

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

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

    assertNotNull(configuration);/*w  w  w. j  a  v  a2  s  . co  m*/
}

From source file:com.base2.kagura.core.authentication.FileAuthentication.java

@Override
public List<Group> getGroups() {
    final String filenameToAdd = "groups.yaml";
    String filename = getFile(filenameToAdd);
    if (filename == null) {
        LOG.error("Can not make directory using paths {}, {}", System.getProperty("user.dir"), configPath);
        return null;
    }//from w  w  w  .  ja  v a 2  s. co  m
    InputStream selectedYaml = openFile(filename);
    if (selectedYaml == null) {
        LOG.error("Can not find: {}", filename);
        return null;
    }
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    List<Group> groups = null;
    try {
        groups = mapper.readValue(selectedYaml, new TypeReference<List<Group>>() {
        });
    } catch (IOException e) {
        LOG.warn("Error parsing {}", filename);
        e.printStackTrace();
    }
    return groups;
}

From source file:com.mugarov.alfapipe.model.programparse.generators.ExtendedCore.java

public final void parseOut() {
    if (this.parseableList != null) {
        try {//w  w w  .j  ava 2  s .  co m
            if (!localFile.exists()) {
                localFile.createNewFile();
            }
            YAMLFactory factory = new YAMLFactory();
            ObjectMapper yamlmap = new ObjectMapper(factory);
            yamlmap.setSerializationInclusion(JsonInclude.Include.NON_NULL);
            FileOutputStream fos = new FileOutputStream(localFile);

            factory.createGenerator(fos).writeObject(this.parseableList);
        } catch (IOException ex) {
            Logger.getLogger(ExtendedCore.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        System.err.println("Error: Not possible to parse out null with " + ExtendedCore.class);
    }
}

From source file:com.mugarov.alfapipe.model.programparse.generators.GeneratorCore.java

public void parseIn() {
    if (this.localFile.length() > 0) {
        try {//from w  w w .j av  a 2 s  .  c o  m
            ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
            ParseableProgram[] result = mapper.readValue(this.localFile, ParseableProgram[].class);
            for (ParseableProgram ass : result) {
                this.available.add(ass);
            }
        } catch (IOException ex) {
            Logger.getLogger(GeneratorCore.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}

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

@Test
public void testLoadComplexObject() throws IOException {
    File configFile = ResourceUtils.getFile("classpath:ea-test.yaml");

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

    configuration.getProperty(TestActor.class, "pushConfigurations", List.class, Collections.emptyList());
}

From source file:org.elasticsoftware.elasticactors.configuration.NodeConfiguration.java

@PostConstruct
public void init() throws IOException {
    // get the yaml resource
    Resource configResource = resourceLoader
            .getResource(env.getProperty("ea.node.config.location", "classpath:ea-default.yaml"));
    // yaml mapper
    ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
    configuration = objectMapper.readValue(configResource.getInputStream(), DefaultConfiguration.class);
    String nodeId = env.getRequiredProperty("ea.node.id");
    InetAddress nodeAddress = InetAddress.getByName(env.getRequiredProperty("ea.node.address"));
    String clusterName = env.getRequiredProperty("ea.cluster");
    node = new ElasticActorsNode(clusterName, nodeId, nodeAddress, configuration);
}