X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/03c30519b11e9772eecdc74f89d350bdecd20361..b266d9a72d427c20ba93098ea87133521dbc4b47:/src/main/java/org/asamk/signal/JsonWriter.java diff --git a/src/main/java/org/asamk/signal/JsonWriter.java b/src/main/java/org/asamk/signal/JsonWriter.java index 8aed4487..20cf7bc1 100644 --- a/src/main/java/org/asamk/signal/JsonWriter.java +++ b/src/main/java/org/asamk/signal/JsonWriter.java @@ -18,22 +18,26 @@ public class JsonWriter { private final Writer writer; private final ObjectMapper objectMapper; - public JsonWriter(final OutputStream writer) { - this.writer = new BufferedWriter(new OutputStreamWriter(writer, StandardCharsets.UTF_8)); + public JsonWriter(final OutputStream outputStream) { + this.writer = new BufferedWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)); objectMapper = new ObjectMapper(); objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.PUBLIC_ONLY); objectMapper.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); } - public void write(final Object object) throws IOException { + public void write(final Object object) { try { - objectMapper.writeValue(writer, object); - } catch (JsonProcessingException e) { - // Some issue with json serialization, probably caused by a bug + try { + objectMapper.writeValue(writer, object); + } catch (JsonProcessingException e) { + // Some issue with json serialization, probably caused by a bug + throw new AssertionError(e); + } + writer.write(System.lineSeparator()); + writer.flush(); + } catch (IOException e) { throw new AssertionError(e); } - writer.write(System.lineSeparator()); - writer.flush(); } }