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:yamlparse.parser.BioboxfileOutparser.java

/**
 * Parsing a ParseableType into a file described by an outputPath
 * @param outputPath is the path where to parse to - please check validity
 * by yourself//from w  w  w  .  ja  v a 2s  .com
 * @param abstractTop should be a BioboxTopType
 */
@Override
public void parse(String outputPath, ParseableType abstractTop) {
    File localFile = new File(outputPath);
    BioboxTopType bbxType = (BioboxTopType) abstractTop;
    try {
        if (!localFile.exists()) {
            localFile.createNewFile();
        }
        this.path = localFile.getAbsolutePath();

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

        FileOutputStream fos = new FileOutputStream(localFile);

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

From source file:org.apache.myriad.BaseConfigurableTest.java

/**
 * This is normally overridden in derived classes. Be sure to invoke this implementation; 
 * otherwise, cfg, cfgWithRole, and cfgWithDocker will all be null.
 * //from w w  w . j av a 2 s  .c o m
 * @throws Exception
 */
@Before
public void setUp() throws Exception {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    cfg = mapper.readValue(getConfURL("myriad-config-test-default.yml"), MyriadConfiguration.class);
    cfgWithRole = mapper.readValue(getConfURL("myriad-config-test-default-with-framework-role.yml"),
            MyriadConfiguration.class);
    cfgWithDocker = mapper.readValue(getConfURL("myriad-config-test-default-with-docker-info.yml"),
            MyriadConfiguration.class);
}

From source file:io.bosh.client.deployments.SpringDeployments.java

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override/* w w w.  j  av  a 2s. co  m*/
public Observable<Deployment> get(String deploymentName) {
    return get(Deployment.class, builder -> builder.pathSegment("deployments", deploymentName))
            .map(response -> {
                response.setName(deploymentName);

                ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
                Map manifestMap = null;
                try {
                    manifestMap = mapper.readValue(response.getRawManifest(), Map.class);
                } catch (IOException e) {
                    throw new DirectorException("Unable to parse deployment manifest", e);
                }
                response.setManifestMap(manifestMap);
                return response;
            });
}

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

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

From source file:com.netflix.spinnaker.fiat.roles.file.FileBasedUserRolesProvider.java

private Map<String, List<Role>> parse(Reader source) throws IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    return mapper.readValue(source, UserRolesMapping.class).toMap();
}

From source file:org.apache.myriad.MyriadTestModule.java

@SuppressWarnings("unchecked")
@Override//from  ww w  .  j  a  va 2s.  c  o m
protected void configure() {

    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    try {
        cfg = mapper.readValue(
                Thread.currentThread().getContextClassLoader().getResource("myriad-config-test-default.yml"),
                MyriadConfiguration.class);
    } catch (IOException e1) {
        LOGGER.error("IOException", e1);
        return;
    }

    if (cfg == null) {
        return;
    }

    bind(MyriadConfiguration.class).toInstance(cfg);

    MapBinder<String, TaskFactory> mapBinder = MapBinder.newMapBinder(binder(), String.class,
            TaskFactory.class);
    mapBinder.addBinding(NodeManagerConfiguration.DEFAULT_NM_TASK_PREFIX).to(NMTaskFactory.class)
            .in(Scopes.SINGLETON);
    Map<String, ServiceConfiguration> auxServicesConfigs = cfg.getServiceConfigurations();
    for (Map.Entry<String, ServiceConfiguration> entry : auxServicesConfigs.entrySet()) {
        String taskFactoryClass = entry.getValue().getTaskFactoryImplName().orNull();
        if (taskFactoryClass != null) {
            try {
                Class<? extends TaskFactory> implClass = (Class<? extends TaskFactory>) Class
                        .forName(taskFactoryClass);
                mapBinder.addBinding(entry.getKey()).to(implClass).in(Scopes.SINGLETON);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        } else {
            mapBinder.addBinding(entry.getKey()).to(ServiceTaskFactory.class).in(Scopes.SINGLETON);
        }
    }
}

From source file:de.qaware.cloud.deployer.kubernetes.resource.deployment.DeploymentLabelUtilTest.java

public void testAddLabel() throws IOException, ResourceException, ResourceConfigException {
    // Add new label
    DeploymentLabelUtil.addLabel(resourceConfig, "test", "test");

    // Read marked deployment
    String markedDeployment = FileUtil.readFileContent(getTestFilePath("deployment-marked.yml"));

    // Check result
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    JsonNode contentTree = mapper.readTree(resourceConfig.getContent());
    JsonNode expectedContentTree = mapper.readTree(markedDeployment);
    assertEquals(expectedContentTree, contentTree);
}

From source file:com.spankingrpgs.util.LoadStateUtils.java

public static void loadCrossGameData(String gameRoot) {
    CharacterFactory characterFactory = new CrimsonCharacterFactory();
    CharacterLoader jsonCharacterLoader = new CharacterLoader(characterFactory);
    CharacterLoader yamlCharacterLoader = new CharacterLoader(characterFactory,
            new ObjectMapper(new YAMLFactory()));

    EventLoader jsonEventLoader = new EventLoader(gameRoot);
    EventLoader yamlEventLoader = new EventLoader(new ObjectMapper(new YAMLFactory()), gameRoot);

    ItemFactory itemFactory = new CrimsonItemFactory();
    ItemLoader jsonItemLoader = new ItemLoader(itemFactory);
    ItemLoader yamlItemLoader = new ItemLoader(itemFactory, new ObjectMapper(new YAMLFactory()));

    try {/*w ww .j av a2  s.  co  m*/
        DynamicTextFunctions.registerFunctions();
        StateModificationCommands.registerCommands();
        CrimsonStateModificationCommands.registerCommands();
        EventPredicates.registerPredicates();

        LoadStateUtils.loadSkills();
        LoadStateUtils.loadJsonData(jsonItemLoader, Paths.get(gameRoot, "data/items"));
        LoadStateUtils.loadYamlData(yamlItemLoader, Paths.get(gameRoot, "data/items"));

        LoadStateUtils.loadJsonData(jsonCharacterLoader, Paths.get(gameRoot, "data/characters"));
        LoadStateUtils.loadYamlData(yamlCharacterLoader, Paths.get(gameRoot, "data/characters"));

        LoadStateUtils.loadJsonData(jsonEventLoader, Paths.get(gameRoot, "data/events"));
        LoadStateUtils.loadYamlData(yamlEventLoader, Paths.get(gameRoot, "data/events"));

        LoadStateUtils.loadBattleMusic(gameRoot);
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "Error encountered while loading.", e);
        System.exit(1);
    }
}

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

/**
 * Read the configuration file from the resources
 * /* w w  w.  j a va 2  s  .c  o m*/
 * @return
 * @throws JsonParseException
 * @throws JsonMappingException
 * @throws IOException
 */
static ServerConfiguration getDefaultConfiguration()
        throws JsonParseException, JsonMappingException, IOException {
    InputStream stream = OpenSearchServer.class.getResourceAsStream("server.yaml");
    if (stream == null)
        throw new IOException("Unable to load the default configuration resource: server.yaml");
    try {
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        return mapper.readValue(stream, ServerConfiguration.class);
    } finally {
        if (stream != null)
            IOUtils.closeQuietly(stream);
    }

}

From source file:com.vmware.photon.controller.common.config.ConfigBuilder.java

private void parse() throws BadConfigException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    try {/*from ww  w  . j av  a 2  s .  c o m*/
        config = mapper.readValue(new File(configFile), configClass);
    } catch (FileNotFoundException e) {
        throw new BadConfigException("Could not find configuration file: " + configFile);
    } catch (JsonProcessingException e) {
        e.printStackTrace();
        throw new BadConfigException("Could not parse configuration: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new BadConfigException("Could not read configuration file" + e.getMessage(), e);
    }
}