Search in sources :

Example 56 with ObjectWriter

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();
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter)

Example 57 with ObjectWriter

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();
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter)

Example 58 with ObjectWriter

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");
    }
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 59 with ObjectWriter

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);
    }
}
Also used : ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter)

Example 60 with ObjectWriter

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);
    }
}
Also used : ExceptionResponse(org.n52.web.exception.ExceptionResponse) OutputStream(java.io.OutputStream) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)140 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)61 IOException (java.io.IOException)31 Test (org.junit.Test)30 File (java.io.File)17 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)15 ArrayList (java.util.ArrayList)12 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)11 JavaType (com.fasterxml.jackson.databind.JavaType)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)7 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 StringWriter (java.io.StringWriter)7 Map (java.util.Map)7 JCommander (com.beust.jcommander.JCommander)6 ParameterException (com.beust.jcommander.ParameterException)6 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)6 RateLimiter (com.google.common.util.concurrent.RateLimiter)6 FileInputStream (java.io.FileInputStream)6