diff options
author | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-12-05 13:56:34 +0100 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-12-05 14:02:05 +0100 |
commit | 23e9f20ebc1b0d013bd3f95a9463a9fe92a2cb44 (patch) | |
tree | 0343335032ebc686ae2d91ebabacb46dfde982f3 /document/src/main/java/com/yahoo/document/json/JsonWriter.java | |
parent | 8890a936e4fddea023fcb94b2841f5b4208ad908 (diff) |
Add tensor short form output option to vespa-visit tool
Specified with `--tensor-short-form`. No single-char option alias,
as short form output will be the default on Vespa 9 and we're running
out of usable option characters for this tool anyway.
Diffstat (limited to 'document/src/main/java/com/yahoo/document/json/JsonWriter.java')
-rw-r--r-- | document/src/main/java/com/yahoo/document/json/JsonWriter.java | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/document/src/main/java/com/yahoo/document/json/JsonWriter.java b/document/src/main/java/com/yahoo/document/json/JsonWriter.java index 05147d2c0ab..04edfeea26e 100644 --- a/document/src/main/java/com/yahoo/document/json/JsonWriter.java +++ b/document/src/main/java/com/yahoo/document/json/JsonWriter.java @@ -93,6 +93,10 @@ public class JsonWriter implements DocumentWriter { this(createPrivateGenerator(out)); } + public JsonWriter(OutputStream out, boolean tensorShortForm) { + this(createPrivateGenerator(out), tensorShortForm); + } + private static JsonGenerator createPrivateGenerator(OutputStream out) { try { return jsonFactory.createGenerator(out); @@ -265,18 +269,29 @@ public class JsonWriter implements DocumentWriter { /** * Utility method to easily serialize a single document. * - * @param document - * the document to be serialized + * @param document the document to be serialized + * @param tensorShortForm whether tensors should be serialized in short form * @return the input document serialised as UTF-8 encoded JSON */ - public static byte[] toByteArray(Document document) { + public static byte[] toByteArray(Document document, boolean tensorShortForm) { ByteArrayOutputStream out = new ByteArrayOutputStream(); - JsonWriter writer = new JsonWriter(out); + JsonWriter writer = new JsonWriter(out, tensorShortForm); writer.write(document); return out.toByteArray(); } /** + * Utility method to easily serialize a single document. + * + * @param document the document to be serialized + * @return the input document serialised as UTF-8 encoded JSON + */ + public static byte[] toByteArray(Document document) { + // TODO Vespa 9: change tensorShortForm default to true + return toByteArray(document, false); + } + + /** * Utility method to easily serialize a single document ID as a remove * operation. * |