use of org.yaml.snakeyaml.Yaml in project pai by Microsoft.
the class YamlUtils method toObject.
public static <T> T toObject(String fileName, Class<T> classRef) throws FileNotFoundException {
Representer representer = new Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(new Constructor(classRef), representer);
return yaml.loadAs(new FileReader(fileName), classRef);
}
use of org.yaml.snakeyaml.Yaml in project be5 by DevelopmentOnTheEdge.
the class YamlSerializer method print.
/**
* This method not just prints the tree. It transforms the tree using following rules:<br>
* - any list of strings with one element is transformed to string;<br>
* - 'true' and 'false' string values is transformed to boolean values.<br>
*
* @param root
* @return
*/
static String print(Object root) {
final DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(FlowStyle.BLOCK);
options.setDefaultScalarStyle(ScalarStyle.PLAIN);
options.setPrettyFlow(false);
final Object transformed = new TreeTransformer().transform(root);
return new Yaml(new Constructor(), new YamlRepresenter(transformed), options).dump(transformed);
}
use of org.yaml.snakeyaml.Yaml in project be5 by DevelopmentOnTheEdge.
the class ModuleLoader2 method getProjectName.
@SuppressWarnings("unchecked")
private static String getProjectName(URL url) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
Map<String, Object> module = (Map<String, Object>) new Yaml().load(reader);
return module.entrySet().iterator().next().getKey();
}
use of org.yaml.snakeyaml.Yaml in project be5 by DevelopmentOnTheEdge.
the class ReadModelFromXmlTest method testWriteReadConnectionProfile.
/**
* Unexpected error when serializing 'connectionUrl' of TestProject/Connection profiles/Local/test
* on windows
* @throws Exception
*/
@Test
public void testWriteReadConnectionProfile() throws Exception {
Assume.assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win"));
final Project project = new Project("TestProject");
BeConnectionProfile profile = new BeConnectionProfile("test", project.getConnectionProfiles().getLocalProfiles());
profile.setConnectionUrl("jdbc:db2://localhost:50000/housing:retrieveMessagesFromServerOnGetMessage=true;");
profile.setUsername("test");
profile.setPassword("password");
LinkedHashMap<String, Object> serializedProfiles = new LinkedHashMap<>();
serializedProfiles.put(profile.getName(), YamlSerializer.serializeProfile(profile));
String serialized = new Yaml().dump(serializedProfiles);
LoadContext loadContext = new LoadContext();
BeConnectionProfile createdProfile = YamlDeserializer.deserializeConnectionProfile(loadContext, serialized, project);
assertNotNull(createdProfile);
if (!loadContext.getWarnings().isEmpty())
throw loadContext.getWarnings().get(0);
assertEquals(profile.getConnectionUrl(), createdProfile.getConnectionUrl());
assertEquals(profile.getUsername(), createdProfile.getUsername());
}
use of org.yaml.snakeyaml.Yaml in project be5 by DevelopmentOnTheEdge.
the class Templates method getTemplatesProject.
public static Project getTemplatesProject() throws ReadException {
Project prj = new Project(TEMPLATES_PROJECT_NAME, true);
LoadContext lc = new LoadContext();
for (String template : TEMPLATES) {
URL url = Templates.class.getResource("templates/" + template + ".yaml");
Node content;
try (InputStream is = url.openStream()) {
content = new Yaml().compose(new InputStreamReader(is, StandardCharsets.UTF_8));
} catch (MarkedYAMLException e) {
throw new ReadException(new Exception((e.getProblemMark().getLine() + 1) + ":" + (e.getProblemMark().getColumn() + 1) + ": " + e.getMessage()), getPath(url), ReadException.LEE_INVALID_STRUCTURE);
} catch (YAMLException | IOException e) {
throw new ReadException(new Exception(e.getMessage()), getPath(url), ReadException.LEE_INVALID_STRUCTURE);
}
try {
Object obj = Serialization.derepresent(content);
@SuppressWarnings("unchecked") Map<String, Object> root = (Map<String, Object>) obj;
@SuppressWarnings("unchecked") Map<String, Object> entityContent = (Map<String, Object>) root.get(template);
DataElementUtils.saveQuiet(YamlDeserializer.readEntity(lc, template, entityContent, prj.getApplication()));
} catch (RuntimeException e) {
throw new ReadException(e, getPath(url), ReadException.LEE_INTERNAL_ERROR);
}
lc.check();
}
return prj;
}
Aggregations