-
-
Notifications
You must be signed in to change notification settings - Fork 151
Closed
Milestone
Description
YAML binary data http://yaml.org/type/binary.html
This code
public void yamlBinaryTest() throws IOException {
StringWriter out = new StringWriter();
YAMLFactory f = new YAMLFactory();
f.disable(Feature.WRITE_DOC_START_MARKER);
f.enable(Feature.MINIMIZE_QUOTES);
YAMLGenerator gen = f.createGenerator(out);
gen.writeStartObject();
gen.writeFieldName("files");
gen.writeStartArray();
for(int i=0; i<=2; i++) {
gen.writeStartObject();
gen.writeStringField("path", "/tmp/"+i+".txt");
byte[] data = "foobar".getBytes("UTF-8");
gen.writeFieldName("content");
gen.writeBinary(Base64Variants.MIME, data, 0, data.length);
gen.writeEndObject();
}
gen.writeEndArray();
gen.writeEndObject();
gen.close();
System.out.println(out);
}
Returns
files:
- path: /tmp/0.txt
content: "Zm9vYmFy"
- path: /tmp/1.txt
content: "Zm9vYmFy"
- path: /tmp/2.txt
content: "Zm9vYmFy"
The expected result
files:
- path: /tmp/0.txt
content: !!binary |
Zm9vYmFy
- path: /tmp/1.txt
content: !!binary |
Zm9vYmFy
- path: /tmp/2.txt
content: !!binary |
Zm9vYmFy
The YAMLGenerator does not support for binary literal.
SnakeYAML(actual low-level decoder/encoder) is having this feature https://bitbucket.org/asomov/snakeyaml/src/190f378138123971777405fbabeab704724b1860/src/main/java/org/yaml/snakeyaml/representer/SafeRepresenter.java?at=default&fileviewer=file-view-default#SafeRepresenter.java-430
Metadata
Metadata
Assignees
Labels
No labels