Json { public static String toJson(Object object) { try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { toJson(object, out); return new String(out.toByteArray(), StandardCharsets.UTF_8); } catch (final IOException ex) { throw new JsonException( "Error in internal toString()-stream.", ex ); } } private  Json(); static String toJson(Object object); static String toJson(Object object, boolean pretty); static void toJson(Object object, OutputStream out); static void toJson(Object object, OutputStream out, boolean pretty); static Object fromJson(String json); static Object fromJson(InputStream in);  }
@TestFactory Stream<DynamicTest> toJson() { final Map<String, Object> testCases = toJsonTestCases(); assertThrows(IllegalArgumentException.class, () -> Json.toJson(new RuntimeException())); return testCases.entrySet().stream().map(testCase -> dynamicTest(testCase.getKey(), () -> { final Object value = testCase.getValue(); final String pretty = Json.toJson(value); assertNotNull(pretty); final String compressed = Json.toJson(value, false); assertNotNull(compressed); final OutputStream prettyOutput = new DataOutputStream(new ByteArrayOutputStream()); final OutputStream compressedOutput = new DataOutputStream(new ByteArrayOutputStream()); Json.toJson(value, prettyOutput); Json.toJson(value, compressedOutput, false); })); }