use of org.yaml.snakeyaml.representer.Representer in project pai by Microsoft.
the class YamlUtils method toObject.
// Bytes <-> Yaml
public static <T> T toObject(byte[] bytes, Class<T> classRef) {
Representer representer = new Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(new Constructor(classRef), representer);
return yaml.loadAs(new String(bytes), classRef);
}
use of org.yaml.snakeyaml.representer.Representer in project mxgwd by kamax-io.
the class YamlConfigLoader method loadFromFile.
public static Config loadFromFile(String path) throws IOException {
Representer rep = new Representer();
rep.getPropertyUtils().setAllowReadOnlyProperties(true);
rep.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(new Constructor(Config.class), rep);
Object o = yaml.load(new FileInputStream(path));
return GsonUtil.get().fromJson(GsonUtil.get().toJson(o), Config.class);
}
use of org.yaml.snakeyaml.representer.Representer in project pom-manipulation-ext by release-engineering.
the class YamlTest method readYamlViaMap.
@Test
public void readYamlViaMap() throws ManipulationException, IOException {
Representer representer = new Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
Yaml y = new Yaml(representer);
Map config = (Map) y.load(new FileInputStream(yamlFile));
Map usersConfig = (Map) config.get("pme");
assertTrue(usersConfig.size() > 0);
}
use of org.yaml.snakeyaml.representer.Representer in project product-mi-tooling by wso2.
the class IOUtils method writeYamlFile.
/**
* Writes k8 secret .yml file
*
* @param filePath file destination
* @param yaml K8SecretYaml object
*/
public static void writeYamlFile(String filePath, K8SecretYaml yaml) {
DumperOptions options = new DumperOptions();
// Configuration to hide the bean type (org.wso2.mi.tooling.security.output.K8SecretYaml)
Representer representer = new Representer();
representer.addClassTag(K8SecretYaml.class, Tag.MAP);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setPrettyFlow(true);
Yaml output = new Yaml(representer, options);
try (FileWriter writer = new FileWriter(filePath)) {
output.dump(yaml, writer);
System.out.println("Kubernetes secret file created in " + filePath + " with default name and namespace");
System.out.println("You can change the default values as required before applying.");
} catch (IOException e) {
throw new EncryptionToolException("Error while creating " + filePath);
}
}
use of org.yaml.snakeyaml.representer.Representer in project dockstore by dockstore.
the class DockstoreYamlHelper method readContent.
private static <T> T readContent(final String content, final Constructor constructor) throws DockstoreYamlException {
try {
// first check to make sure there aren't any unsafe types
final Yaml safeYaml = new Yaml(new SafeConstructor());
safeYaml.load(content);
Representer representer = new Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
final Yaml yaml = new Yaml(constructor, representer);
return yaml.load(content);
} catch (Exception e) {
final String exceptionMsg = e.getMessage();
String errorMsg = ERROR_READING_DOCKSTORE_YML;
errorMsg += exceptionMsg;
LOG.error(errorMsg, e);
throw new DockstoreYamlException(errorMsg);
}
}
Aggregations