use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project jackson-core by FasterXML.
the class TestJDKSerializability method _copyJson.
@SuppressWarnings("resource")
protected String _copyJson(JsonFactory f, String json, boolean useBytes) throws IOException {
if (useBytes) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
JsonGenerator jg = f.createGenerator(bytes);
_copyJson(f, json, jg);
return bytes.toString("UTF-8");
}
StringWriter sw = new StringWriter();
JsonGenerator jg = f.createGenerator(sw);
_copyJson(f, json, jg);
return sw.toString();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project jackson-databind by FasterXML.
the class TestGeneratorUsingMapper method testPojoWriting.
/*
/**********************************************************
/* Tests for data binding integration
/**********************************************************
*/
public void testPojoWriting() throws IOException {
JsonFactory jf = new MappingJsonFactory();
StringWriter sw = new StringWriter();
JsonGenerator gen = jf.createGenerator(sw);
gen.writeObject(new Pojo());
gen.close();
// trimming needed if main-level object has leading space
String act = sw.toString().trim();
assertEquals("{\"x\":4}", act);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project jackson-databind by FasterXML.
the class SequenceWriterTest method testSimpleArray.
public void testSimpleArray() throws Exception {
StringWriter strw = new StringWriter();
SequenceWriter w = WRITER.writeValuesAsArray(strw);
w.write(new Bean(1)).write(new Bean(2)).writeAll(new Bean[] { new Bean(-7), new Bean(2) });
w.close();
assertEquals(aposToQuotes("[{'a':1},{'a':2},{'a':-7},{'a':2}]"), strw.toString());
strw = new StringWriter();
JsonGenerator gen = WRITER.getFactory().createGenerator(strw);
w = WRITER.writeValuesAsArray(gen);
Collection<Bean> bean = Collections.singleton(new Bean(3));
w.write(new Bean(1)).write(null).writeAll((Iterable<Bean>) bean);
w.close();
gen.close();
assertEquals(aposToQuotes("[{'a':1},null,{'a':3}]"), strw.toString());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project jackson-databind by FasterXML.
the class SerializationFeaturesTest method testFlushingNotAutomatic.
public void testFlushingNotAutomatic() throws IOException {
// but should not occur if configured otherwise
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FLUSH_AFTER_WRITE_VALUE, false);
StringWriter sw = new StringWriter();
JsonGenerator g = mapper.getFactory().createGenerator(sw);
mapper.writeValue(g, Integer.valueOf(13));
// no flushing now:
assertEquals("", sw.toString());
// except when actually flushing
g.flush();
assertEquals("13", sw.toString());
g.close();
// Also, same should happen with ObjectWriter
sw = new StringWriter();
g = mapper.getFactory().createGenerator(sw);
ObjectWriter ow = mapper.writer();
ow.writeValue(g, Integer.valueOf(99));
assertEquals("", sw.toString());
// except when actually flushing
g.flush();
assertEquals("99", sw.toString());
g.close();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator in project geode by apache.
the class JSONUtils method formulateJsonForListQueriesCall.
public static String formulateJsonForListQueriesCall(Region<String, String> queryRegion) {
HeapDataOutputStream outputStream = new HeapDataOutputStream(org.apache.geode.internal.Version.CURRENT);
try {
JsonGenerator generator = enableDisableJSONGeneratorFeature(getObjectMapper().getFactory().createGenerator((OutputStream) outputStream, JsonEncoding.UTF8));
JsonWriter.writeQueryListAsJson(generator, "queries", queryRegion);
generator.close();
return new String(outputStream.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
} finally {
outputStream.close();
}
}
Aggregations