List of usage examples for com.fasterxml.jackson.core JsonGenerator writeEndArray
public abstract void writeEndArray() throws IOException, JsonGenerationException;
From source file:com.predic8.membrane.core.interceptor.statistics.StatisticsProvider.java
private void createJson(Exchange exc, ResultSet r, int offset, int max, int total) throws IOException, JsonGenerationException, SQLException { StringWriter jsonTxt = new StringWriter(); JsonGenerator jsonGen = jsonFactory.createGenerator(jsonTxt); jsonGen.writeStartObject();/*from w ww. j ava 2 s. co m*/ jsonGen.writeArrayFieldStart("statistics"); int size = 0; r.absolute(offset + 1); //jdbc doesn't support paginating. This can be inefficient. while (size < max && !r.isAfterLast()) { size++; writeRecord(r, jsonGen); r.next(); } jsonGen.writeEndArray(); jsonGen.writeNumberField("total", total); jsonGen.writeEndObject(); jsonGen.flush(); createResponse(exc, jsonTxt); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.brat.internal.model.BratAnnotationDocument.java
public void write(JsonGenerator aJG, String aText) throws IOException { aJG.writeStartObject();/*www. j av a2 s . c o m*/ aJG.writeStringField("text", aText); aJG.writeFieldName("entities"); aJG.writeStartArray(); for (BratAnnotation ann : annotations.values()) { if (ann instanceof BratTextAnnotation) { ann.write(aJG); } } aJG.writeEndArray(); aJG.writeFieldName("relations"); aJG.writeStartArray(); for (BratAnnotation ann : annotations.values()) { if (ann instanceof BratRelationAnnotation) { ann.write(aJG); } } aJG.writeEndArray(); aJG.writeFieldName("triggers"); aJG.writeStartArray(); for (BratAnnotation ann : annotations.values()) { if (ann instanceof BratEventAnnotation) { ((BratEventAnnotation) ann).getTriggerAnnotation().write(aJG); } } aJG.writeEndArray(); aJG.writeFieldName("events"); aJG.writeStartArray(); for (BratAnnotation ann : annotations.values()) { if (ann instanceof BratEventAnnotation) { ann.write(aJG); } } aJG.writeEndArray(); aJG.writeFieldName("attributes"); aJG.writeStartArray(); for (BratAnnotation ann : annotations.values()) { for (BratAttribute attr : ann.getAttributes()) { attr.write(aJG); } } aJG.writeEndArray(); aJG.writeEndObject(); }
From source file:de.alexkamp.sandbox.ChrootSandboxProcess.java
public void toJson(JsonGenerator sender) throws IOException { sender.writeStartObject();// w w w . j av a2 s .com sender.writeObjectField("WorkDir", getWorkdir()); sender.writeObjectField("Executable", getExecutable()); sender.writeObjectField("Timeout", getTimeout()); sender.writeArrayFieldStart("Arguments"); for (String arg : getArgs()) { sender.writeString(arg); } sender.writeEndArray(); sender.writeEndObject(); }
From source file:com.strategicgains.hyperexpress.serialization.siren.jackson.SirenResourceSerializer.java
private void writeLinks(SirenResource resource, JsonGenerator jgen) throws JsonGenerationException, IOException { List<Link> links = resource.getLinks(); if (links.isEmpty()) return;//from w w w. ja va 2 s . c om jgen.writeArrayFieldStart(LINKS); Map<String, SirenLink> linksByRel = indexLinksByHref(resource.getLinks()); for (SirenLink link : linksByRel.values()) { jgen.writeObject(link); } jgen.writeEndArray(); }
From source file:com.messagehub.samples.servlet.MessageList.java
/** * Build message list dependent on the format Message Hub requires. The * message list is in the form: [{ "value": base_64_string }, ...] * * @return {String} String representation of a JSON object. * @throws IOException// w w w . j a v a2 s .c o m */ public String build() throws IOException { final JsonFactory jsonFactory = new JsonFactory(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); JsonGenerator jsonGenerator = null; jsonGenerator = jsonFactory.createGenerator(outputStream); jsonGenerator.writeStartArray(); // Write each message as a JSON object in // the form: // { "value": base_64_string } for (int i = 0; i < this.messages.size(); i++) { jsonGenerator.writeStartObject(); jsonGenerator.writeFieldName("value"); jsonGenerator.writeObject(this.messages.get(i)); jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); // Close underlying streams and return string representation. jsonGenerator.close(); outputStream.close(); return new String(outputStream.toByteArray()); }
From source file:org.springframework.data.elasticsearch.core.DefaultResultMapper.java
private String buildJSONFromFields(Collection<SearchHitField> values) { JsonFactory nodeFactory = new JsonFactory(); try {/* w w w. j ava2s. com*/ ByteArrayOutputStream stream = new ByteArrayOutputStream(); JsonGenerator generator = nodeFactory.createGenerator(stream, JsonEncoding.UTF8); generator.writeStartObject(); for (SearchHitField value : values) { if (value.getValues().size() > 1) { generator.writeArrayFieldStart(value.getName()); for (Object val : value.getValues()) { generator.writeObject(val); } generator.writeEndArray(); } else { generator.writeObjectField(value.getName(), value.getValue()); } } generator.writeEndObject(); generator.flush(); return new String(stream.toByteArray(), Charset.forName("UTF-8")); } catch (IOException e) { return null; } }
From source file:com.nebhale.cyclinglibrary.web.json.TypeJsonSerializer.java
@Override public void serialize(Type value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject();/*from w w w .ja v a 2s . co m*/ jgen.writeStringField("name", value.getName()); jgen.writeStringField("shortName", value.getShortName()); jgen.writeArrayFieldStart("links"); jgen.writeObject(new Link("self", "types", value)); jgen.writeObject(new Link("create-collection", "types", value, "collections")); for (Long collectiondId : value.getCollectionIds()) { jgen.writeObject(new Link("collection", "types", value, "collections", collectiondId)); } jgen.writeEndArray(); jgen.writeEndObject(); }
From source file:com.attribyte.essem.es.SearchRequest.java
private void generateFields(final JsonGenerator generator) throws IOException { generator.writeArrayFieldStart("fields"); if (fields.contains("*")) { generator.writeString("*"); } else {// w w w.j ava 2 s. c o m for (String field : fields) { generator.writeString(field); } } generator.writeEndArray(); }
From source file:com.predic8.membrane.core.interceptor.administration.AdminRESTInterceptor.java
@Mapping("/admin/rest/exchanges(/?\\?.*)?") public Response getExchanges(QueryParameter params, String relativeRootPath) throws Exception { if (params.getString("waitForModification") != null) { getRouter().getExchangeStore().waitForModification(params.getLong("waitForModification")); }//from w w w .ja v a 2 s .c o m List<AbstractExchange> exchanges; synchronized (getRouter().getExchangeStore().getAllExchangesAsList()) { exchanges = new ArrayList<AbstractExchange>(getRouter().getExchangeStore().getAllExchangesAsList()); } exchanges = filter(params, exchanges); Collections.sort(exchanges, ComparatorFactory.getAbstractExchangeComparator( params.getString("sort", "time"), params.getString("order", "desc"))); int offset = params.getInt("offset", 0); int max = params.getInt("max", exchanges.size()); final int total = exchanges.size(); final List<AbstractExchange> paginated = exchanges.subList(offset, Math.min(offset + max, exchanges.size())); return json(new JSONContent() { public void write(JsonGenerator gen) throws Exception { gen.writeStartObject(); gen.writeArrayFieldStart("exchanges"); for (AbstractExchange e : paginated) { writeExchange(e, gen); } gen.writeEndArray(); gen.writeNumberField("total", total); gen.writeNumberField("lastModified", getRouter().getExchangeStore().getLastModified()); gen.writeEndObject(); } }); }
From source file:ratpack.codahale.metrics.internal.WebSocketReporter.java
private void writeCounters(JsonGenerator json, SortedMap<String, Counter> counters) throws IOException { json.writeArrayFieldStart("counters"); for (Map.Entry<String, Counter> entry : counters.entrySet()) { Counter counter = entry.getValue(); json.writeStartObject();/*w w w . j ava2 s . com*/ json.writeStringField("name", entry.getKey()); json.writeNumberField("count", counter.getCount()); json.writeEndObject(); } json.writeEndArray(); }