use of org.finos.legend.engine.plan.execution.result.serialization.Serializer in project legend-engine by finos.
the class TestJsonStreamingResult method doesNotAutocloseJsonArrays.
private void doesNotAutocloseJsonArrays(SerializationFormat format) throws Exception {
JsonStreamingResult result = new JsonStreamingResult(x -> {
try {
x.writeStartArray();
// throw before closing array to mimic streaming error
throw new TestException();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}, null);
Serializer serializer = result.getSerializer(format);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
serializer.stream(outputStream);
} catch (TestException e) {
try {
new ObjectMapper().readTree(outputStream.toByteArray());
Assert.fail("Serialized bytes should not contians valid JSON. Is Jackson autoclosing arrays and objects?");
} catch (JsonEOFException eofException) {
assertThat(eofException, hasMessage(CoreMatchers.startsWith("Unexpected end-of-input: expected close marker for Array")));
}
}
}
use of org.finos.legend.engine.plan.execution.result.serialization.Serializer in project legend-sdlc by finos.
the class LegendPureV1TestCase method getResultAsJson.
private JsonNode getResultAsJson(Result result) {
if (result instanceof StreamingResult) {
try {
Serializer serializer = ((StreamingResult) result).getSerializer(SerializationFormat.DEFAULT);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(1024);
serializer.stream(byteStream);
return objectMapper.readTree(byteStream.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (result instanceof ConstantResult) {
Object value = ((ConstantResult) result).getValue();
return objectMapper.valueToTree(value);
}
throw new RuntimeException("Unhandled result type: " + result.getClass().getSimpleName());
}
use of org.finos.legend.engine.plan.execution.result.serialization.Serializer in project legend-engine by finos.
the class MappingTestRunner method getResultAsJson.
private JsonNode getResultAsJson(Result result) {
if (result instanceof StreamingResult) {
try {
Serializer serializer = ((StreamingResult) result).getSerializer(SerializationFormat.DEFAULT);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(1024);
serializer.stream(byteStream);
return objectMapper.readTree(byteStream.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (result instanceof ConstantResult) {
Object value = ((ConstantResult) result).getValue();
return objectMapper.valueToTree(value);
}
throw new RuntimeException("Unhandled result type: " + result.getClass().getSimpleName());
}
Aggregations