List of usage examples for com.fasterxml.jackson.core JsonGenerator writeStartObject
public abstract void writeStartObject() throws IOException, JsonGenerationException;
From source file:de.alexkamp.sandbox.ChrootSandboxProcess.java
public void toJson(JsonGenerator sender) throws IOException { sender.writeStartObject(); sender.writeObjectField("WorkDir", getWorkdir()); sender.writeObjectField("Executable", getExecutable()); sender.writeObjectField("Timeout", getTimeout()); sender.writeArrayFieldStart("Arguments"); for (String arg : getArgs()) { sender.writeString(arg);//from w ww . jav a2s .c o m } sender.writeEndArray(); sender.writeEndObject(); }
From source file:com.cedarsoft.couchdb.io.CouchDocSerializer.java
public <T> void serialize(@Nonnull CouchDoc<T> doc, @Nonnull JacksonSerializer<? super T> wrappedSerializer, @Nonnull JsonGenerator generator) throws IOException { generator.writeStartObject(); RawCouchDocSerializer.serializeIdAndRev(generator, doc); //Type//from w w w . j ava 2 s . co m generator.writeStringField(AbstractJacksonSerializer.PROPERTY_TYPE, wrappedSerializer.getType()); //Version generator.writeStringField(AbstractJacksonSerializer.PROPERTY_VERSION, wrappedSerializer.getFormatVersion().format()); //The wrapped object wrappedSerializer.serialize(generator, doc.getObject(), wrappedSerializer.getFormatVersion()); //The attachments - placed at the end serializeInlineAttachments(doc, generator); generator.writeEndObject(); }
From source file:com.proofpoint.event.client.EventFieldMetadata.java
private void writeMap(JsonGenerator jsonGenerator, Map<?, ?> value, Deque<Object> objectStack) throws IOException { jsonGenerator.writeStartObject(); for (Map.Entry<?, ?> entry : value.entrySet()) { jsonGenerator.writeFieldName((String) entry.getKey()); writeFieldValue(jsonGenerator, entry.getValue(), objectStack); }/* w ww .j a v a2s .co m*/ jsonGenerator.writeEndObject(); }
From source file:com.sdl.odata.renderer.json.writer.JsonServiceDocumentWriter.java
/** * The main method for Writer./* w w w . j a v a2s .c om*/ * It builds the service root document according to spec. * * @return output in json * @throws ODataRenderException If unable to render the json service document */ public String buildJson() throws ODataRenderException { LOG.debug("Start building Json service root document"); try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(stream, JsonEncoding.UTF8); jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(CONTEXT, getContextURL(uri, entityDataModel)); jsonGenerator.writeArrayFieldStart(VALUE); List<EntitySet> entities = entityDataModel.getEntityContainer().getEntitySets(); for (EntitySet entity : entities) { if (entity.isIncludedInServiceDocument()) { writeObject(jsonGenerator, entity); } } List<Singleton> singletons = entityDataModel.getEntityContainer().getSingletons(); for (Singleton singleton : singletons) { writeObject(jsonGenerator, singleton); } jsonGenerator.writeEndArray(); jsonGenerator.writeEndObject(); jsonGenerator.close(); return stream.toString(StandardCharsets.UTF_8.name()); } catch (IOException e) { throw new ODataRenderException("It is unable to render service document", e); } }
From source file:org.echocat.marquardt.common.serialization.PublicKeySerializer.java
@Override public void serialize(final PublicKey publicKey, final JsonGenerator jsonGenerator, final com.fasterxml.jackson.databind.SerializerProvider serializerProvider) throws IOException { final PublicKeyWithMechanism publicKeyWithMechanism = new PublicKeyWithMechanism(publicKey); jsonGenerator.writeStartObject(); jsonGenerator.writeBinaryField(KEY, publicKeyWithMechanism.getContent()); jsonGenerator.writeEndObject();/*w w w .j ava 2s . co m*/ }
From source file:ratpack.codahale.metrics.internal.WebSocketReporter.java
@Override @SuppressWarnings("rawtypes") public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { try {/*w w w. j av a2s .co m*/ OutputStream out = new ByteArrayOutputStream(); JsonGenerator json = factory.createGenerator(out); json.writeStartObject(); json.writeNumberField("timestamp", clock.getTime()); writeTimers(json, timers); writeGauges(json, gauges); writeMeters(json, meters); writeCounters(json, counters); writeHistograms(json, histograms); json.writeEndObject(); json.flush(); json.close(); metricsBroadcaster.broadcast(out.toString()); } catch (IOException e) { LOGGER.log(Level.WARNING, "Exception encountered while reporting metrics: " + e.getLocalizedMessage()); } }
From source file:com.proofpoint.event.client.EventFieldMetadata.java
private void writeMultimap(JsonGenerator jsonGenerator, Multimap<?, ?> value, Deque<Object> objectStack) throws IOException { jsonGenerator.writeStartObject(); for (Map.Entry<?, ? extends Collection<?>> entry : value.asMap().entrySet()) { jsonGenerator.writeFieldName((String) entry.getKey()); writeArray(jsonGenerator, entry.getValue(), objectStack); }//from w w w . j av a 2s. c o m jsonGenerator.writeEndObject(); }
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(); 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++;//from w w w. ja v a 2 s . c om writeRecord(r, jsonGen); r.next(); } jsonGen.writeEndArray(); jsonGen.writeNumberField("total", total); jsonGen.writeEndObject(); jsonGen.flush(); createResponse(exc, jsonTxt); }
From source file:com.greglturnquist.embeddablesdr.SystemDependencySerializer.java
@Override public void serialize(final SystemDependency systemDependency, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { Link link = entityLinks.linkToSingleResource(System.class, systemDependency.getTarget().getId()); jgen.writeStartObject(); jgen.writeStringField("description", systemDependency.getDescription()); jgen.writeObjectFieldStart("_links"); jgen.writeObjectFieldStart("target"); jgen.writeStringField("href", link.getHref()); jgen.writeEndObject();/*from w w w. java 2s . c om*/ jgen.writeEndObject(); jgen.writeEndObject(); }
From source file:net.openhft.chronicle.wire.benchmarks.Data.java
public void writeTo(JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeNumberField("price", price); generator.writeBooleanField("flag", flag); generator.writeStringField("text", text.toString()); generator.writeStringField("side", side.name()); generator.writeNumberField("smallInt", smallInt); generator.writeNumberField("longInt", longInt); generator.close();/*from w w w. j a v a2s . co m*/ }