Skip to content

Commit

Permalink
Valid json when using jsonproto output in queries
Browse files Browse the repository at this point in the history
  • Loading branch information
chiragramani committed Jun 15, 2023
1 parent fed23d5 commit 86478e4
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
* An output formatter that outputs a protocol buffer json representation of a query result and
Expand All @@ -40,10 +42,13 @@ public OutputFormatterCallback<Target> createPostFactoStreamCallback(
@Override
public void processOutput(Iterable<Target> partialResult)
throws IOException, InterruptedException {
List<String> jsonProtoBuffers = new ArrayList<>();
for (Target target : partialResult) {
out.write(
jsonPrinter.print(toTargetProtoBuffer(target)).getBytes(StandardCharsets.UTF_8));
jsonProtoBuffers.add(jsonPrinter.omittingInsignificantWhitespace().print(toTargetProtoBuffer(target)));
}
out.write("[".getBytes(StandardCharsets.UTF_8));
out.write(String.join(",", jsonProtoBuffers).getBytes(StandardCharsets.UTF_8));
out.write("]".getBytes(StandardCharsets.UTF_8));
}
};
}
Expand Down

0 comments on commit 86478e4

Please sign in to comment.