use of org.codehaus.jackson.JsonGenerator in project neo4j by neo4j.
the class GraphExtractionWriterTest method write.
private JsonNode write(Map<String, Object> row) throws IOException, JsonParseException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
JsonGenerator json = jsonFactory.createJsonGenerator(out);
json.writeStartObject();
try {
new GraphExtractionWriter().write(json, row.keySet(), new MapRow(row), checker);
} finally {
json.writeEndObject();
json.flush();
}
return JsonHelper.jsonNode(out.toString(UTF_8.name()));
}
use of org.codehaus.jackson.JsonGenerator in project neo4j by neo4j.
the class RowWriterTests method shouldWriteNestedMaps.
@Test
public void shouldWriteNestedMaps() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
JsonGenerator json = new JsonFactory(new Neo4jJsonCodec()).createJsonGenerator(out);
JsonNode row = serialize(out, json, new RowWriter());
MatcherAssert.assertThat(row.size(), equalTo(1));
JsonNode firstCell = row.get(0);
MatcherAssert.assertThat(firstCell.get("one").get("two").size(), is(2));
MatcherAssert.assertThat(firstCell.get("one").get("two").get(0).asBoolean(), is(true));
MatcherAssert.assertThat(firstCell.get("one").get("two").get(1).get("three").asInt(), is(42));
}
use of org.codehaus.jackson.JsonGenerator in project stanbol by apache.
the class AnalyzedTextSerializer method serialize.
/**
* Serializes the parsed {@link AnalysedText} to the {@link OutputStream} by
* using the {@link Charset}.
* @param at the {@link AnalysedText} to serialize
* @param out the {@link OutputStream}
* @param charset the {@link Charset}. UTF-8 is used as default if <code>null</code>
* is parsed
*/
public void serialize(AnalysedText at, OutputStream out, Charset charset) throws IOException {
if (at == null) {
throw new IllegalArgumentException("The parsed AnalysedText MUST NOT be NULL!");
}
if (out == null) {
throw new IllegalArgumentException("The parsed OutputStream MUST NOT be NULL");
}
if (charset == null) {
charset = UTF8;
}
JsonFactory jsonFactory = mapper.getJsonFactory();
JsonGenerator jg = jsonFactory.createJsonGenerator(new OutputStreamWriter(out, charset));
jg.useDefaultPrettyPrinter();
jg.writeStartObject();
jg.writeArrayFieldStart("spans");
jg.writeTree(writeSpan(at));
for (Iterator<Span> it = at.getEnclosed(EnumSet.allOf(SpanTypeEnum.class)); it.hasNext(); ) {
jg.writeTree(writeSpan(it.next()));
}
jg.writeEndArray();
jg.writeEndObject();
jg.close();
}
use of org.codehaus.jackson.JsonGenerator in project hive by apache.
the class JsonMetaDataFormatter method showErrors.
@Override
public void showErrors(DataOutputStream out, WMValidateResourcePlanResponse response) throws HiveException {
JsonGenerator generator = null;
try {
generator = new ObjectMapper().getJsonFactory().createJsonGenerator(out);
generator.writeStartObject();
generator.writeArrayFieldStart("errors");
for (String error : response.getErrors()) {
generator.writeString(error);
}
generator.writeEndArray();
generator.writeArrayFieldStart("warnings");
for (String error : response.getWarnings()) {
generator.writeString(error);
}
generator.writeEndArray();
generator.writeEndObject();
} catch (IOException e) {
throw new HiveException(e);
} finally {
if (generator != null) {
IOUtils.closeQuietly(generator);
}
}
}
Aggregations