Search in sources :

Example 1 with YamlConfig

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());
}
Also used : YamlConfig(com.esotericsoftware.yamlbeans.YamlConfig) LinkedHashMap(java.util.LinkedHashMap) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter) Test(org.junit.Test)

Example 2 with YamlConfig

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();
}
Also used : YamlConfig(com.esotericsoftware.yamlbeans.YamlConfig) StringWriter(java.io.StringWriter) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter)

Example 3 with YamlConfig

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());
}
Also used : YamlConfig(com.esotericsoftware.yamlbeans.YamlConfig) StringWriter(java.io.StringWriter) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter) Test(org.junit.Test)

Example 4 with YamlConfig

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());
}
Also used : YamlConfig(com.esotericsoftware.yamlbeans.YamlConfig) StringWriter(java.io.StringWriter) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter) Test(org.junit.Test)

Example 5 with YamlConfig

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);
}
Also used : YamlConfig(com.esotericsoftware.yamlbeans.YamlConfig) StringWriter(java.io.StringWriter) YamlReader(com.esotericsoftware.yamlbeans.YamlReader) YamlWriter(com.esotericsoftware.yamlbeans.YamlWriter) Test(org.junit.Test)

Aggregations

YamlConfig (com.esotericsoftware.yamlbeans.YamlConfig)9 YamlWriter (com.esotericsoftware.yamlbeans.YamlWriter)9 Test (org.junit.Test)8 StringWriter (java.io.StringWriter)6 LinkedHashMap (java.util.LinkedHashMap)2 YamlReader (com.esotericsoftware.yamlbeans.YamlReader)1 ArrayList (java.util.ArrayList)1