Skip to content

Commit

Permalink
Use singleton JsonFactory while serializing
Browse files Browse the repository at this point in the history
Factory is used to create generators/parsers and it can be shared
  • Loading branch information
wendigo committed Feb 8, 2025
1 parent 5455de3 commit a7f7591
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
public class JsonQueryDataEncoder
implements QueryDataEncoder
{
private static final JsonFactory JSON_FACTORY = jsonFactory();
private static final String ENCODING = "json";
private final Session session;
private final TypeEncoder[] typeEncoders;
Expand All @@ -60,9 +61,8 @@ public JsonQueryDataEncoder(Session session, List<OutputColumn> columns)
public DataAttributes encodeTo(OutputStream output, List<Page> pages)
throws IOException
{
JsonFactory jsonFactory = jsonFactory();
ConnectorSession connectorSession = session.toConnectorSession();
try (CountingOutputStream wrapper = new CountingOutputStream(output); JsonGenerator generator = jsonFactory.createGenerator(wrapper)) {
try (CountingOutputStream wrapper = new CountingOutputStream(output); JsonGenerator generator = JSON_FACTORY.createGenerator(wrapper)) {
writePagesToJsonGenerator(connectorSession, e -> { throw e; }, generator, typeEncoders, sourcePageChannels, pages);
return DataAttributes.builder()
.set(SEGMENT_SIZE, toIntExact(wrapper.getCount()))
Expand Down

0 comments on commit a7f7591

Please sign in to comment.