use of org.yaml.snakeyaml.Yaml in project incubator-servicecomb-java-chassis by apache.
the class LocalServiceRegistryClientImpl method initFromData.
private void initFromData(InputStream is) {
Yaml yaml = new Yaml();
@SuppressWarnings("unchecked") Map<String, Object> data = yaml.loadAs(is, Map.class);
initFromData(data);
}
use of org.yaml.snakeyaml.Yaml in project gitpitch by gitpitch.
the class YAMLOptions method build.
public static YAMLOptions build(PitchParams pp, GRSService grsService, DiskService diskService) {
YAMLOptions yOpts = null;
try {
/*
* Instantiate YAML parser.
*/
Yaml yaml = new Yaml();
/*
* Build path to PITCHME_YAML on disk.
*/
Path yPath = diskService.asPath(pp, PITCHME_YAML);
File yFile = yPath.toFile();
if (yFile.exists()) {
/*
* Use YAML parser to transform YAML properties to Map.
*/
Map<String, String> yProps = (Map<String, String>) yaml.load(new FileReader(yPath.toFile()));
/*
* Handle PITCHME.yaml empty file without properites.
*/
if (yProps == null) {
yProps = new HashMap<String, String>();
}
log.debug("build: pp={}, props={}", pp, yProps);
yOpts = new YAMLOptions(yProps, grsService);
} else {
log.debug("build: pp={}, yaml not found={}", yFile);
}
} catch (Exception yex) {
log.warn("build: pp={}, parsing YAML ex={}", pp, yex);
} finally {
return yOpts;
}
}
use of org.yaml.snakeyaml.Yaml in project wombat by PLOS.
the class RootConfiguration method yaml.
@Bean
public Yaml yaml() {
final Yaml yaml;
if (ignoreMissingProperty) {
final Constructor contructor = new IgnoreMissingPropertyConstructor();
yaml = new Yaml(contructor);
} else {
yaml = new Yaml();
}
return yaml;
}
use of org.yaml.snakeyaml.Yaml in project wombat by PLOS.
the class Theme method readYamlConfigValues.
private Map<?, ?> readYamlConfigValues(Theme theme, String configPath) throws IOException {
// We don't actually validate whether a *.json file is valid JSON or just YAML.
try (InputStream yamlStream = theme.fetchStaticResource(configPath + ".yaml");
InputStream jsonStream = theme.fetchStaticResource(configPath + ".json")) {
if (yamlStream == null && jsonStream == null) {
return null;
} else if (yamlStream != null && jsonStream != null) {
String message = String.format("Redundant files at %s.yaml and %s.json in theme \"%s\"", configPath, configPath, theme.getKey());
throw new IllegalStateException(message);
}
InputStream streamToUse = (yamlStream != null) ? yamlStream : jsonStream;
// don't cache; it isn't threadsafe
Yaml yaml = new Yaml();
return yaml.loadAs(new InputStreamReader(streamToUse), Map.class);
}
}
use of org.yaml.snakeyaml.Yaml in project weblogic-kubernetes-operator by oracle.
the class YamlUtils method newYaml.
public static Yaml newYaml() {
// always make a new yaml object since it appears to be stateful
// so there are problems if you try to use the same one to
// parse different yamls at the same time
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setPrettyFlow(true);
return new Yaml(new MyConstructor(), new MyRepresenter(), options);
}
Aggregations