List of usage examples for com.fasterxml.jackson.core JsonGenerator writeStringField
public void writeStringField(String fieldName, String value) throws IOException, JsonGenerationException
From source file:net.opentsdb.tree.Tree.java
/** * Converts the object to a JSON byte array, necessary for CAS calls and to * keep redundant data down/*from www. j a va2s .c o m*/ * @return A byte array with the serialized tree */ private byte[] toStorageJson() { // TODO - precalc how much memory to grab final ByteArrayOutputStream output = new ByteArrayOutputStream(); try { final JsonGenerator json = JSON.getFactory().createGenerator(output); json.writeStartObject(); // we only need to write a small amount of information //json.writeNumberField("treeId", tree_id); json.writeStringField("name", name); json.writeStringField("description", description); json.writeStringField("notes", notes); json.writeBooleanField("strictMatch", strict_match); json.writeNumberField("created", created); json.writeBooleanField("enabled", enabled); json.writeBooleanField("storeFailures", store_failures); json.writeEndObject(); json.close(); // TODO zero copy? return output.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.apache.olingo.server.core.serializer.json.ODataJsonSerializer.java
void writeContextURL(final ContextURL contextURL, final JsonGenerator json) throws IOException { if (!isODataMetadataNone && contextURL != null) { json.writeStringField(constants.getContext(), ContextURLBuilder.create(contextURL).toASCIIString()); }/*from w w w . java 2 s.c om*/ }
From source file:org.apache.olingo.server.core.serializer.json.ODataJsonSerializer.java
private void srid(final JsonGenerator jgen, final SRID srid) throws IOException { jgen.writeObjectFieldStart(Constants.JSON_CRS); jgen.writeStringField(Constants.ATTR_TYPE, Constants.JSON_NAME); jgen.writeObjectFieldStart(Constants.PROPERTIES); jgen.writeStringField(Constants.JSON_NAME, "EPSG:" + srid.toString()); jgen.writeEndObject();/* w w w. j a va 2 s. c o m*/ jgen.writeEndObject(); }
From source file:org.apache.olingo.server.core.serializer.json.ODataJsonSerializer.java
void writeInlineCount(final String propertyName, final Integer count, final JsonGenerator json) throws IOException { if (count != null) { if (isIEEE754Compatible) { json.writeStringField(propertyName + constants.getCount(), String.valueOf(count)); } else {/*from w w w .j a v a2s.c o m*/ json.writeNumberField(propertyName + constants.getCount(), count); } } }
From source file:org.apache.olingo.server.core.serializer.json.ODataJsonSerializer.java
void writeDeltaLink(final AbstractEntityCollection entitySet, final JsonGenerator json, boolean pagination) throws IOException { if (entitySet.getDeltaLink() != null && !pagination) { json.writeStringField(constants.getDeltaLink(), entitySet.getDeltaLink().toASCIIString()); }// w ww . j a v a2s .co m }
From source file:com.google.openrtb.json.OpenRtbJsonWriter.java
protected void writeGeoFields(Geo geo, JsonGenerator gen) throws IOException { if (geo.hasLat()) { gen.writeNumberField("lat", geo.getLat()); }/*from w ww . j a v a 2s . c om*/ if (geo.hasLon()) { gen.writeNumberField("lon", geo.getLon()); } if (geo.hasType()) { gen.writeNumberField("type", geo.getType().getNumber()); } if (geo.hasCountry()) { gen.writeStringField("country", geo.getCountry()); } if (geo.hasRegion()) { gen.writeStringField("region", geo.getRegion()); } if (geo.hasRegionfips104()) { gen.writeStringField("regionfips104", geo.getRegionfips104()); } if (geo.hasMetro()) { gen.writeStringField("metro", geo.getMetro()); } if (geo.hasCity()) { gen.writeStringField("city", geo.getCity()); } if (geo.hasZip()) { gen.writeStringField("zip", geo.getZip()); } if (geo.hasUtcoffset()) { gen.writeNumberField("utcoffset", geo.getUtcoffset()); } if (geo.hasAccuracy()) { gen.writeNumberField("accuracy", geo.getAccuracy()); } if (geo.hasLastfix()) { gen.writeNumberField("lastfix", geo.getLastfix()); } if (geo.hasIpservice()) { gen.writeNumberField("ipservice", geo.getIpservice().getNumber()); } }
From source file:org.apache.olingo.server.core.serializer.json.ODataJsonSerializer.java
void writeNextLink(final AbstractEntityCollection entitySet, final JsonGenerator json, boolean pagination) throws IOException { if (entitySet.getNext() != null) { pagination = true;//from w w w.j a v a 2s .c om json.writeStringField(constants.getNextLink(), entitySet.getNext().toASCIIString()); } else { pagination = false; } }
From source file:org.apache.olingo.server.core.serializer.json.ODataJsonSerializer.java
@Override public SerializerResult reference(final ServiceMetadata metadata, final EdmEntitySet edmEntitySet, final Entity entity, final ReferenceSerializerOptions options) throws SerializerException { OutputStream outputStream = null; SerializerException cachedException = null; try {/*from ww w. j av a 2 s. co m*/ final ContextURL contextURL = checkContextURL(options == null ? null : options.getContextURL()); CircleStreamBuffer buffer = new CircleStreamBuffer(); final UriHelper uriHelper = new UriHelperImpl(); outputStream = buffer.getOutputStream(); final JsonGenerator json = new JsonFactory().createGenerator(outputStream); json.writeStartObject(); writeContextURL(contextURL, json); json.writeStringField(constants.getId(), uriHelper.buildCanonicalURL(edmEntitySet, entity)); json.writeEndObject(); json.close(); outputStream.close(); return SerializerResultImpl.with().content(buffer.getInputStream()).build(); } catch (final IOException e) { cachedException = new SerializerException(IO_EXCEPTION_TEXT, e, SerializerException.MessageKeys.IO_EXCEPTION); throw cachedException; } finally { closeCircleStreamBufferOutput(outputStream, cachedException); } }
From source file:org.createnet.raptor.models.objects.serializer.RecordSetSerializer.java
@Override public void serialize(RecordSet r, JsonGenerator jg, SerializerProvider sp) throws IOException { final Stream stream = r.getStream(); ServiceObject obj = null;//from w w w. j a v a2 s . c o m if (stream != null) { obj = stream.getServiceObject(); } jg.writeStartObject(); jg.writeObjectFieldStart("channels"); for (Map.Entry<String, IRecord> item : r.channels.entrySet()) { String channelName = item.getKey(); IRecord channel = item.getValue(); // enforce stream schema if available if (r.getStream() != null) { if (!r.getStream().channels.containsKey(channelName)) { // skip unmanaged field return; } } if (channel == null) { continue; } if (channel.getValue() == null) { continue; } jg.writeObjectField(channelName, channel.getValue()); // jg.writeObjectFieldStart(channelName); // jg.writeObjectField("current-value", channel.getValue()); // jg.writeEndObject(); } jg.writeEndObject(); jg.writeNumberField("timestamp", r.getTimestampTime()); // try to get a value if (r.userId == null && obj != null) { r.userId = obj.userId; } if (r.userId != null) { jg.writeStringField("userId", r.userId); } // try to get a value if (r.objectId == null && obj != null) { r.objectId = obj.id; } if (r.objectId != null) { jg.writeStringField("objectId", r.objectId); } // try to get a value if (r.streamId == null && stream != null) { r.streamId = stream.name; } if (r.streamId != null) { jg.writeStringField("streamId", r.streamId); } jg.writeEndObject(); }