use of com.esotericsoftware.yamlbeans.YamlConfig in project yamlbeans by EsotericSoftware.
the class EmitterTest method testStateFlowMapingKey.
@Test
public void testStateFlowMapingKey() throws YamlException {
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("key1", "value1");
map.put("key2", "value2");
YamlConfig yamlConfig = new YamlConfig();
yamlConfig.writeConfig.setFlowStyle(true);
yamlConfig.writeConfig.setWriteRootTags(false);
YamlWriter yamlWriter = new YamlWriter(stringWriter, yamlConfig);
yamlWriter.write(map);
yamlWriter.close();
assertEquals("{key1: value1, key2: value2}" + LINE_SEPARATOR, stringWriter.toString());
}
use of com.esotericsoftware.yamlbeans.YamlConfig in project yamlbeans by EsotericSoftware.
the class YamlDocumentTest method writeDocument.
private String writeDocument(YamlDocument yaml) throws YamlException {
StringWriter writer = new StringWriter();
YamlConfig config = new YamlConfig();
config.writeConfig.setExplicitFirstDocument(yaml.getTag() != null);
config.writeConfig.setWriteClassname(WriteClassName.NEVER);
config.writeConfig.setAutoAnchor(false);
YamlWriter yamlWriter = new YamlWriter(writer, config);
yamlWriter.write(yaml);
yamlWriter.close();
return writer.toString();
}
use of com.esotericsoftware.yamlbeans.YamlConfig in project yamlbeans by EsotericSoftware.
the class EmitterWriterTest method testWriteFolded.
@Test
public void testWriteFolded() throws YamlException {
YamlConfig yamlConfig = new YamlConfig();
yamlConfig.writeConfig.setQuoteChar(Quote.FOLDED);
StringWriter stringWriter = new StringWriter();
YamlWriter yamlWriter = new YamlWriter(stringWriter, yamlConfig);
yamlWriter.write("111\n222 333");
yamlWriter.close();
assertEquals(">-" + LINE_SEPARATOR + " 111" + LINE_SEPARATOR + LINE_SEPARATOR + " 222 333" + LINE_SEPARATOR, stringWriter.toString());
}
use of com.esotericsoftware.yamlbeans.YamlConfig in project yamlbeans by EsotericSoftware.
the class EmitterWriterTest method testWriteLiteral.
@Test
public void testWriteLiteral() throws YamlException {
YamlConfig yamlConfig = new YamlConfig();
yamlConfig.writeConfig.setQuoteChar(Quote.LITERAL);
StringWriter stringWriter = new StringWriter();
YamlWriter yamlWriter = new YamlWriter(stringWriter, yamlConfig);
yamlWriter.write("111\n222");
yamlWriter.close();
assertEquals("|-" + LINE_SEPARATOR + " 111" + LINE_SEPARATOR + " 222" + LINE_SEPARATOR, stringWriter.toString());
}
use of com.esotericsoftware.yamlbeans.YamlConfig in project yamlbeans by EsotericSoftware.
the class Issue37Test method test.
@Test
public void test() throws YamlException {
TestObject testObject = new TestObject();
testObject.sexType = SexType.FEMALE;
YamlConfig yamlConfig = new YamlConfig();
yamlConfig.setScalarSerializer(SexType.class, new SexTypeSerializer());
StringWriter sw = new StringWriter();
YamlWriter writer = new YamlWriter(sw, yamlConfig);
writer.write(testObject);
writer.close();
System.out.println(sw.toString());
assertEquals("!com.esotericsoftware.yamlbeans.issues.issue37.TestObject" + LINE_SEPARATOR + "sexType: female" + LINE_SEPARATOR, sw.toString());
YamlReader reader = new YamlReader(sw.toString(), yamlConfig);
TestObject obj = reader.read(TestObject.class);
assertEquals(SexType.FEMALE, obj.sexType);
}
Aggregations