@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);
    }));
}