use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project fastjson by alibaba.
the class Jackson2AfterBurnCodec method encode.
@Override
public void encode(OutputStream out, Object object) throws Exception {
Class<?> clazz = object.getClass();
JsonGenerator generator = constructGenerator(out);
JavaType type = mapper.getTypeFactory().constructType(clazz);
ObjectWriter writer = mapper.writerFor(type);
writer.writeValue(generator, object);
generator.close();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project fastjson by alibaba.
the class Jackson2Codec method encode.
@Override
public void encode(OutputStream out, Object object) throws Exception {
Class<?> clazz = object.getClass();
JsonGenerator generator = constructGenerator(out);
JavaType type = mapper.getTypeFactory().constructType(clazz);
ObjectWriter writer = mapper.writerFor(type);
writer.writeValue(generator, object);
generator.flush();
generator.close();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project OpenRefine by OpenRefine.
the class TestUtils method isSerializedTo.
/**
* Checks that a serializable object is serialized to the target JSON string.
*
* @throws IOException
*/
public static void isSerializedTo(Object o, String targetJson, boolean saveMode) {
// also check Jackson serialization
try {
ObjectWriter writer = null;
if (saveMode) {
writer = ParsingUtilities.saveWriter;
} else {
writer = ParsingUtilities.defaultWriter;
}
String jacksonJson = writer.writeValueAsString(o);
assertEqualsAsJson(jacksonJson, targetJson);
} catch (JsonProcessingException e) {
e.printStackTrace();
fail("jackson serialization failed");
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project immutables by immutables.
the class JsonChecker method assertSameJson.
private void assertSameJson(JsonNode expected) throws JsonProcessingException {
Objects.requireNonNull(expected, "expected");
if (!actual.equals(expected)) {
ObjectWriter writer = MAPPER.writerWithDefaultPrettyPrinter();
String expectedPretty = writer.writeValueAsString(expected);
String actualPretty = writer.writeValueAsString(actual);
Assertions.assertEquals(expectedPretty, actualPretty);
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter in project series-rest-api by 52North.
the class BaseController method writeExceptionResponse.
private void writeExceptionResponse(WebException e, HttpServletResponse response, HttpStatus status) {
final String logMessage = "An exception occured: \n {}";
if (status == HttpStatus.INTERNAL_SERVER_ERROR) {
LOGGER.error(logMessage, e);
} else {
LOGGER.debug(logMessage, e);
}
// TODO consider using a 'suppress_response_codes=true' parameter and always return 200 OK
response.setStatus(status.value());
response.setContentType(Constants.MimeType.APPLICATION_JSON.getMimeType());
ObjectMapper objectMapper = createObjectMapper();
ObjectWriter writer = objectMapper.writerFor(ExceptionResponse.class);
ExceptionResponse exceptionResponse = ExceptionResponse.createExceptionResponse(e, status);
try (OutputStream outputStream = response.getOutputStream()) {
writer.writeValue(outputStream, exceptionResponse);
} catch (IOException ioe) {
LOGGER.error("Could not process error message.", ioe);
}
}
Aggregations