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:de.thomaskrille.dropwizard.environment_configuration.EnvironmentConfigurationFactory.java

/**
 * Creates a new configuration factory for the given class.
 *
 * @param klass//from  w w  w  .ja v a  2 s . co  m
 *        the configuration class
 * @param validator
 *        the validator to use
 * @param objectMapper
 *        the Jackson {@link ObjectMapper} to use
 * @param propertyPrefix
 *        the system property name prefix used by overrides
 */
public EnvironmentConfigurationFactory(final Class<T> klass, final Validator validator,
        final ObjectMapper objectMapper, final String propertyPrefix, EnvironmentProvider environmentProvider) {
    super(klass, validator, objectMapper, propertyPrefix);
    this.klass = klass;
    this.propertyPrefix = propertyPrefix.endsWith(".") ? propertyPrefix : propertyPrefix + '.';
    this.mapper = objectMapper.copy();
    mapper.enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    this.validator = validator;
    this.yamlFactory = new YAMLFactory();
    this.environmentProvider = environmentProvider;
}

From source file:org.walkmod.conf.providers.YAMLConfigurationProvider.java

public YAMLConfigurationProvider(String fileName) {
    this.fileName = fileName;
    factory = new YAMLFactory();
    mapper = new ObjectMapper(factory);
    factory.configure(YAMLGenerator.Feature.WRITE_DOC_START_MARKER, false);
}

From source file:com.netflix.spinnaker.clouddriver.artifacts.helm.IndexParser.java

private IndexConfig buildIndexConfig(InputStream in) throws IOException {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    IndexConfig indexConfig;/*  ww  w  .ja  va 2  s.  co  m*/
    try {
        indexConfig = mapper.readValue(in, IndexConfig.class);
    } catch (IOException e) {
        throw new IOException("Invalid index.yaml file in repository " + repository);
    }
    return indexConfig;
}

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

@Override
public List<User> getUsers() {
    final String filenameToAdd = "users.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.j av  a2  s  . c om*/
    InputStream selectedYaml = openFile(filename);
    if (selectedYaml == null) {
        LOG.error("Can not find: {}", filename);
        return null;
    }
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    List<User> users = null;
    try {
        users = mapper.readValue(selectedYaml, new TypeReference<List<User>>() {
        });
    } catch (IOException e) {
        LOG.warn("Error parsing {}", filename);
        e.printStackTrace();
    }
    return users;
}

From source file:com.vmware.photon.controller.deployer.dcp.ContainersConfigTest.java

@Test
public void buildsValidConfgiuration() throws Exception {
    String path = this.getClass().getResource("/configurations").getPath();
    List<File> leafDirectories = findAllLeafDirectories(new File(path));
    for (File dir : leafDirectories) {
        File configYml = findFile(dir, "yml");
        if (configYml != null) {
            File releaseJson = findFile(dir, "release.json");
            Map<String, Object> dynamicParamters = new HashMap<>(defaultDynamicParamters);
            @SuppressWarnings("unchecked")
            Map<String, Object> d = Utils.fromJson(FileUtils.readFileToString(releaseJson), Map.class);
            dynamicParamters.putAll(d);//  w w w. ja  v a  2 s  .  c o  m
            MustacheFactory mustacheFactory = new DefaultMustacheFactory();
            Mustache mustache = mustacheFactory.compile(new InputStreamReader(new FileInputStream(configYml)),
                    configYml.getName());
            StringWriter stringWriter = new StringWriter();
            mustache.execute(stringWriter, dynamicParamters).flush();
            stringWriter.flush();

            // validating that the created yml file can be read
            ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
            mapper.readValue(stringWriter.toString(), Object.class);
        }
    }
}

From source file:grakn.core.daemon.executor.Storage.java

private void initialiseConfig() {
    try {/*ww  w.j a  v a 2s . co m*/
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory().enable(YAMLGenerator.Feature.MINIMIZE_QUOTES));
        TypeReference<Map<String, Object>> reference = new TypeReference<Map<String, Object>>() {
        };
        ByteArrayOutputStream outputstream = new ByteArrayOutputStream();

        // Read the original Cassandra config from services/cassandra/cassandra.yaml into a String
        byte[] oldConfigBytes = Files.readAllBytes(Paths.get(STORAGE_CONFIG_PATH, STORAGE_CONFIG_NAME));
        String oldConfig = new String(oldConfigBytes, StandardCharsets.UTF_8);

        // Convert the String of config values into a Map
        Map<String, Object> oldConfigMap = mapper.readValue(oldConfig, reference);
        oldConfigMap = Maps.transformValues(oldConfigMap, value -> value == null ? EMPTY_VALUE : value);

        // Set the original config as the starting point of the new config values
        Map<String, Object> newConfigMap = new HashMap<>(oldConfigMap);

        // Read the Grakn config which is available to the user
        Config inputConfig = Config
                .read(Paths.get(Objects.requireNonNull(SystemProperty.CONFIGURATION_FILE.value())));

        // Set the new data directories for Cassandra
        String newDataDir = inputConfig.getProperty(ConfigKey.DATA_DIR);
        newConfigMap.put(DATA_FILE_DIR_CONFIG_KEY, Collections.singletonList(newDataDir + DATA_SUBDIR));
        newConfigMap.put(SAVED_CACHES_DIR_CONFIG_KEY, newDataDir + SAVED_CACHES_SUBDIR);
        newConfigMap.put(COMMITLOG_DIR_CONFIG_KEY, newDataDir + COMMITLOG_SUBDIR);

        // Overwrite Cassandra config values with values provided in the Grakn config
        inputConfig.properties().stringPropertyNames().stream().filter(key -> key.contains(CONFIG_PARAM_PREFIX))
                .forEach(key -> newConfigMap.put(key.replaceAll(CONFIG_PARAM_PREFIX, ""),
                        inputConfig.properties().getProperty(key)));

        // Write the new Cassandra config into the original file: services/cassandra/cassandra.yaml
        mapper.writeValue(outputstream, newConfigMap);
        String newConfigStr = outputstream.toString(StandardCharsets.UTF_8.name());
        Files.write(Paths.get(STORAGE_CONFIG_PATH, STORAGE_CONFIG_NAME),
                newConfigStr.getBytes(StandardCharsets.UTF_8));

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.github.jrubygradle.jem.Gem.java

private static ObjectMapper getYamlMapper() {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    return mapper;
}

From source file:io.fabric8.devops.ProjectConfigs.java

/**
 * Creates a configured Jackson object mapper for parsing YAML
 *///w  w w . j a va  2s .  c o  m
public static ObjectMapper createObjectMapper() {
    return new ObjectMapper(new YAMLFactory());
}

From source file:org.mayocat.shop.cart.internal.DefaultCartLoaderTest.java

private CartTestDefinition loadTest(String name) throws IOException {

    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

    String test = Resources.toString(Resources.getResource("tests/" + name), Charsets.UTF_8);

    return mapper.readValue(test, CartTestDefinition.class);
}

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

@Override
public List<User> getUsers() {
    String urlSuffix = "users";
    InputStream selectedYaml = httpGet(urlSuffix);
    if (selectedYaml == null) {
        LOG.error("Can not find: {}", urlSuffix);
        return null;
    }//  w  w w .jav  a  2s .  c om
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    List<User> users = null;
    try {
        users = mapper.readValue(selectedYaml, new TypeReference<List<User>>() {
        });
    } catch (IOException e) {
        LOG.warn("Error parsing {}", urlSuffix);
        e.printStackTrace();
    }
    return users;
}