List of usage examples for com.fasterxml.jackson.core JsonGenerator writeEndArray
public abstract void writeEndArray() throws IOException, JsonGenerationException;
From source file:ratpack.codahale.metrics.internal.WebSocketReporter.java
private void writeMeters(JsonGenerator json, SortedMap<String, Meter> meters) throws IOException { json.writeArrayFieldStart("meters"); for (Map.Entry<String, Meter> entry : meters.entrySet()) { Meter meter = entry.getValue();/* w w w. j av a2 s .co m*/ json.writeStartObject(); json.writeStringField("name", entry.getKey()); json.writeNumberField("count", meter.getCount()); json.writeNumberField("meanRate", convertRate(meter.getMeanRate())); json.writeNumberField("oneMinuteRate", convertRate(meter.getOneMinuteRate())); json.writeNumberField("fiveMinuteRate", convertRate(meter.getFiveMinuteRate())); json.writeNumberField("fifteenMinuteRate", convertRate(meter.getFifteenMinuteRate())); json.writeEndObject(); } json.writeEndArray(); }
From source file:models.CategorySerializer.java
@Override public void serialize(Category cat, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject();// w ww. j a va2 s . co m jgen.writeStringField("id", cat.getId()); jgen.writeStringField("label", cat.getLabel()); jgen.writeFieldName("children"); jgen.writeStartArray(); for (Object obj : cat.getChildren()) { if (obj instanceof Group) { Group group = (Group) obj; jgen.writeStartObject(); jgen.writeStringField("id", group.getId()); jgen.writeStringField("label", group.getLabel()); if (group.getType() == Type.PROCESS) { jgen.writeStringField("type", "PROCESS"); } else { jgen.writeStringField("type", "COEFFICIENT"); } jgen.writeEndObject(); } else { jgen.writeObject(obj); } } jgen.writeEndArray(); jgen.writeEndObject(); }
From source file:com.github.aptd.simulation.elements.train.CDoor.java
@Override protected void writeState(final JsonGenerator p_generator) throws IOException { p_generator.writeStringField("state", m_state.name()); p_generator.writeNumberField("openwidth", m_openwidth); p_generator.writeStringField("station", m_stationid); p_generator.writeStringField("platform", m_platformid); p_generator.writeNumberField("freetime", m_freetime); p_generator.writeArrayFieldStart("entryqueue"); for (final IPassenger<?> l_passenger : m_entryqueue) p_generator.writeString(l_passenger.id()); p_generator.writeEndArray(); p_generator.writeArrayFieldStart("exitqueue"); for (final IPassenger<?> l_passenger : m_exitqueue) p_generator.writeString(l_passenger.id()); p_generator.writeEndArray();// w w w . j av a 2s . c o m }
From source file:TDS.Shared.Messages.MessageJson.java
public String create(ContextType contextType, List<String> contexts) throws ReturnStatusException { MessageContextType messageContextType = null; StringWriter sw = new StringWriter(); JsonFactory jsonFactory = new JsonFactory(); JsonGenerator jsonWriter; try {//from ww w .j a v a2s. co m if (_messageSystem != null) { messageContextType = _messageSystem.getMessageContextType(contextType); } if (messageContextType == null) return "{}"; jsonWriter = jsonFactory.createGenerator(sw); jsonWriter.writeStartObject(); jsonWriter.writeStringField("c_l", _language); // "c_l": _language jsonWriter.writeFieldName("c_a"); // "c_a" : jsonWriter.writeStartArray(); // [ for (String context : contexts) { MessageContext messageContext = messageContextType.getContext(context); writeContextElement(messageContext, jsonWriter); } jsonWriter.writeEndArray(); // ] jsonWriter.writeEndObject(); // } jsonWriter.close(); sw.close(); } catch (IOException e) { ReturnStatus rs = new ReturnStatus("failed", "Serialization failed: " + e.getMessage()); throw new ReturnStatusException(rs); } return sw.getBuffer().toString(); }
From source file:org.tanrabad.survey.service.json.MultiPolygonTypeConverter.java
@Override public void serialize(List<JsonPolygon> coordinateMultiPolygon, String fieldName, boolean writeFieldNameForObject, JsonGenerator jsonGenerator) throws IOException { if (coordinateMultiPolygon != null) { jsonGenerator.writeFieldName("coordinates"); jsonGenerator.writeStartArray(); for (JsonPolygon eachPolygon : coordinateMultiPolygon) { if (eachPolygon != null) { jsonGenerator.writeStartArray(); writePolygonArray(jsonGenerator, eachPolygon.getBoundary()); for (int subPolygonIndex = 0; subPolygonIndex < eachPolygon .getHolesCount(); subPolygonIndex++) { List<Location> holePolygon = eachPolygon.getHole(subPolygonIndex); if (holePolygon != null) { writePolygonArray(jsonGenerator, holePolygon); }//from w ww . j av a 2 s.c o m } jsonGenerator.writeEndArray(); } } } jsonGenerator.writeEndArray(); }
From source file:com.joliciel.jochre.search.highlight.HighlightManagerImpl.java
@Override public void findSnippets(Highlighter highlighter, Set<Integer> docIds, Set<String> fields, Writer out) { try {//from ww w . j a v a 2s . c om Map<Integer, Set<HighlightTerm>> termMap = highlighter.highlight(docIds, fields); Map<Integer, List<Snippet>> snippetMap = this.findSnippets(docIds, fields, termMap, this.getSnippetCount(), this.getSnippetSize()); JsonFactory jsonFactory = new JsonFactory(); JsonGenerator jsonGen = jsonFactory.createGenerator(out); jsonGen.writeStartObject(); for (int docId : docIds) { Document doc = indexSearcher.doc(docId); jsonGen.writeObjectFieldStart(doc.get("id")); jsonGen.writeStringField("path", doc.get("path")); jsonGen.writeNumberField("docId", docId); jsonGen.writeArrayFieldStart("snippets"); for (Snippet snippet : snippetMap.get(docId)) { snippet.toJson(jsonGen, df); } jsonGen.writeEndArray(); if (includeText) { jsonGen.writeArrayFieldStart("snippetText"); for (Snippet snippet : snippetMap.get(docId)) { jsonGen.writeStartObject(); jsonGen.writeStringField("snippet", this.displaySnippet(docId, snippet)); jsonGen.writeEndObject(); } jsonGen.writeEndArray(); } if (includeGraphics) { jsonGen.writeArrayFieldStart("snippetGraphics"); for (Snippet snippet : snippetMap.get(docId)) { jsonGen.writeStartObject(); ImageSnippet imageSnippet = this.getImageSnippet(snippet); jsonGen.writeNumberField("left", imageSnippet.getRectangle().getLeft()); jsonGen.writeNumberField("top", imageSnippet.getRectangle().getTop()); jsonGen.writeNumberField("right", imageSnippet.getRectangle().getRight()); jsonGen.writeNumberField("bottom", imageSnippet.getRectangle().getBottom()); jsonGen.writeArrayFieldStart("highlights"); for (Rectangle highlight : imageSnippet.getHighlights()) { jsonGen.writeStartObject(); jsonGen.writeNumberField("left", highlight.getLeft()); jsonGen.writeNumberField("top", highlight.getTop()); jsonGen.writeNumberField("right", highlight.getRight()); jsonGen.writeNumberField("bottom", highlight.getBottom()); jsonGen.writeEndObject(); } jsonGen.writeEndArray(); jsonGen.writeEndObject(); } jsonGen.writeEndArray(); } jsonGen.writeEndObject(); } // next doc jsonGen.writeEndObject(); jsonGen.flush(); } catch (IOException ioe) { LogUtils.logError(LOG, ioe); throw new RuntimeException(ioe); } }
From source file:com.predic8.membrane.core.interceptor.administration.AdminRESTInterceptor.java
@Mapping("/admin/rest/clients(/?\\?.*)?") public Response getClients(QueryParameter params, String relativeRootPath) throws Exception { final List<? extends ClientStatistics> clients = getRouter().getExchangeStore().getClientStatistics(); Collections.sort(clients, ComparatorFactory.getClientStatisticsComparator(params.getString("sort", "name"), params.getString("order", "asc"))); int offset = params.getInt("offset", 0); int max = params.getInt("max", clients.size()); final int total = clients.size(); final List<? extends ClientStatistics> paginated = clients.subList(offset, Math.min(offset + max, clients.size())); return json(new JSONContent() { public void write(JsonGenerator gen) throws Exception { gen.writeStartObject();// w w w . j ava2 s.com gen.writeArrayFieldStart("clients"); for (ClientStatistics s : paginated) { gen.writeStartObject(); gen.writeStringField("name", s.getClient()); gen.writeNumberField("count", s.getCount()); gen.writeNumberField("min", s.getMinDuration()); gen.writeNumberField("max", s.getMaxDuration()); gen.writeNumberField("avg", s.getAvgDuration()); gen.writeEndObject(); } gen.writeEndArray(); gen.writeNumberField("total", total); gen.writeEndObject(); } }); }
From source file:org.neo4j.ontology.server.unmanaged.AnnotationResource.java
private void writeJsonNodeObject(JsonGenerator jg, Node term, Label annotationLabel, List<Long> dataSetsId) throws IOException { jg.writeStartObject(); // { jg.writeStringField("uri", term.getProperty("uri").toString()); // uri: "http://www.w3.org/2002/07/owl#Thing" jg.writeStringField("ontId", term.getProperty("name").toString()); // ontId: "OWL:Thing" jg.writeStringField("label", term.getProperty("rdfs:label", term.getProperty("name")).toString()); // ontId: "OWL:Thing" jg.writeFieldName("dataSets"); // dataSets: jg.writeStartArray(); // [ for (Long dataSetId : dataSetsId) { jg.writeNumber(dataSetId); // 123 }// w w w . j ava2 s .c o m jg.writeEndArray(); // ] writeJsonNodeObjectParents(jg, term, annotationLabel); jg.writeEndObject(); // } }
From source file:com.joliciel.jochre.search.highlight.HighlightManagerImpl.java
@Override public void highlight(Highlighter highlighter, Set<Integer> docIds, Set<String> fields, Writer out) { try {//from ww w .j a v a 2 s . c o m Map<Integer, Set<HighlightTerm>> termMap = highlighter.highlight(docIds, fields); JsonFactory jsonFactory = new JsonFactory(); JsonGenerator jsonGen = jsonFactory.createGenerator(out); jsonGen.writeStartObject(); for (int docId : docIds) { Document doc = indexSearcher.doc(docId); jsonGen.writeObjectFieldStart(doc.get("id")); jsonGen.writeStringField("path", doc.get("path")); jsonGen.writeNumberField("docId", docId); jsonGen.writeArrayFieldStart("terms"); for (HighlightTerm term : termMap.get(docId)) { fields.add(term.getField()); term.toJson(jsonGen, df); } jsonGen.writeEndArray(); if (includeText) { for (String field : fields) { jsonGen.writeObjectFieldStart("field" + field); Set<HighlightTerm> terms = termMap.get(docId); jsonGen.writeStringField("contents", this.displayHighlights(docId, field, terms)); jsonGen.writeEndObject(); } } jsonGen.writeEndObject(); } jsonGen.writeEndObject(); jsonGen.flush(); } catch (IOException ioe) { LogUtils.logError(LOG, ioe); throw new RuntimeException(ioe); } }