Search in sources :

Example 81 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project debezium by debezium.

the class JacksonWriter method write.

@Override
public String write(Document document) throws IOException {
    StringWriter writer = new StringWriter();
    try (JsonGenerator jsonGenerator = factory.createGenerator(writer)) {
        configure(jsonGenerator);
        writeDocument(document, jsonGenerator);
    }
    return writer.getBuffer().toString();
}
Also used : StringWriter(java.io.StringWriter) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 82 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project debezium by debezium.

the class JacksonWriter method write.

@Override
public void write(Array array, OutputStream jsonStream) throws IOException {
    try (JsonGenerator jsonGenerator = factory.createGenerator(jsonStream)) {
        configure(jsonGenerator);
        writeArray(array, jsonGenerator);
    }
}
Also used : JsonGenerator(com.fasterxml.jackson.core.JsonGenerator)

Example 83 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project credhub by cloudfoundry-incubator.

the class TimeModuleFactory method createTimeModule.

public static JavaTimeModule createTimeModule() {
    JavaTimeModule javaTimeModule = new JavaTimeModule();
    javaTimeModule.addSerializer(Instant.class, new JsonSerializer<Instant>() {

        @Override
        public void serialize(Instant value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
            gen.writeString(ZonedDateTime.ofInstant(value, ZoneId.of("UTC")).format(TIMESTAMP_FORMAT));
        }
    });
    return javaTimeModule;
}
Also used : JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) Instant(java.time.Instant) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider)

Example 84 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project calcite by apache.

the class DruidQueryFilterTest method testInFilter.

@Test
public void testInFilter() throws IOException {
    final Fixture f = new Fixture();
    final List<? extends RexNode> listRexNodes = ImmutableList.of(f.rexBuilder.makeInputRef(f.varcharRowType, 0), f.rexBuilder.makeExactLiteral(BigDecimal.valueOf(1)), f.rexBuilder.makeExactLiteral(BigDecimal.valueOf(5)), f.rexBuilder.makeLiteral("value1"));
    RexNode inRexNode = f.rexBuilder.makeCall(SqlStdOperatorTable.IN, listRexNodes);
    DruidJsonFilter returnValue = DruidJsonFilter.toDruidFilters(inRexNode, f.varcharRowType, druidQuery);
    Assert.assertNotNull("Filter is null", returnValue);
    JsonFactory jsonFactory = new JsonFactory();
    final StringWriter sw = new StringWriter();
    JsonGenerator jsonGenerator = jsonFactory.createGenerator(sw);
    returnValue.write(jsonGenerator);
    jsonGenerator.close();
    Assert.assertThat(sw.toString(), is("{\"type\":\"in\",\"dimension\":\"dimensionName\"," + "\"values\":[\"1\",\"5\",\"value1\"]}"));
}
Also used : StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Example 85 with JsonGenerator

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project calcite by apache.

the class DruidQueryFilterTest method testBetweenFilterStringCase.

@Test
public void testBetweenFilterStringCase() throws IOException {
    final Fixture f = new Fixture();
    final List<RexNode> listRexNodes = ImmutableList.of(f.rexBuilder.makeLiteral(false), f.rexBuilder.makeInputRef(f.varcharRowType, 0), f.rexBuilder.makeLiteral("lower-bound"), f.rexBuilder.makeLiteral("upper-bound"));
    RelDataType relDataType = f.typeFactory.createSqlType(SqlTypeName.BOOLEAN);
    RexNode betweenRexNode = f.rexBuilder.makeCall(relDataType, SqlStdOperatorTable.BETWEEN, listRexNodes);
    DruidJsonFilter returnValue = DruidJsonFilter.toDruidFilters(betweenRexNode, f.varcharRowType, druidQuery);
    Assert.assertNotNull("Filter is null", returnValue);
    JsonFactory jsonFactory = new JsonFactory();
    final StringWriter sw = new StringWriter();
    JsonGenerator jsonGenerator = jsonFactory.createGenerator(sw);
    returnValue.write(jsonGenerator);
    jsonGenerator.close();
    Assert.assertThat(sw.toString(), is("{\"type\":\"bound\",\"dimension\":\"dimensionName\",\"lower\":\"lower-bound\"," + "\"lowerStrict\":false,\"upper\":\"upper-bound\",\"upperStrict\":false," + "\"ordering\":\"lexicographic\"}"));
}
Also used : StringWriter(java.io.StringWriter) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) RelDataType(org.apache.calcite.rel.type.RelDataType) RexNode(org.apache.calcite.rex.RexNode) Test(org.junit.Test)

Aggregations

JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)704 KriptonJsonContext (com.abubusoft.kripton.KriptonJsonContext)257 KriptonByteArrayOutputStream (com.abubusoft.kripton.common.KriptonByteArrayOutputStream)257 KriptonRuntimeException (com.abubusoft.kripton.exception.KriptonRuntimeException)257 JacksonWrapperSerializer (com.abubusoft.kripton.persistence.JacksonWrapperSerializer)257 IOException (java.io.IOException)169 StringWriter (java.io.StringWriter)144 JsonFactory (com.fasterxml.jackson.core.JsonFactory)101 ByteArrayOutputStream (java.io.ByteArrayOutputStream)66 Map (java.util.Map)57 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)54 HashMap (java.util.HashMap)40 Test (org.junit.Test)30 File (java.io.File)27 ArrayList (java.util.ArrayList)25 OutputStream (java.io.OutputStream)24 Writer (java.io.Writer)22 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)21 SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)20 FileOutputStream (java.io.FileOutputStream)19