Java Code Examples for com.fasterxml.jackson.core.JsonGenerator#writeStringField()
The following examples show how to use
com.fasterxml.jackson.core.JsonGenerator#writeStringField() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeminarBindMap.java From kripton with Apache License 2.0 | 6 votes |
@Override public int serializeOnJackson(Seminar object, JsonGenerator jacksonSerializer) throws Exception { jacksonSerializer.writeStartObject(); int fieldCount=0; // Serialized Field: // field id (mapped with "id") fieldCount++; jacksonSerializer.writeNumberField("id", object.id); // field location (mapped with "location") if (object.location!=null) { fieldCount++; jacksonSerializer.writeStringField("location", object.location); } // field name (mapped with "name") if (object.name!=null) { fieldCount++; jacksonSerializer.writeStringField("name", object.name); } jacksonSerializer.writeEndObject(); return fieldCount; }
Example 2
Source File: PersonBindMap.java From kripton with Apache License 2.0 | 6 votes |
@Override public int serializeOnJacksonAsString(Person object, JsonGenerator jacksonSerializer) throws Exception { jacksonSerializer.writeStartObject(); int fieldCount=0; // Serialized Field: // field id (mapped with "id") jacksonSerializer.writeStringField("id", PrimitiveUtils.writeLong(object.getId())); // field name (mapped with "name") if (object.getName()!=null) { fieldCount++; jacksonSerializer.writeStringField("name", object.getName()); } jacksonSerializer.writeEndObject(); return fieldCount; }
Example 3
Source File: SchemaParser.java From iceberg with Apache License 2.0 | 6 votes |
static void toJson(Types.MapType map, JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeStringField(TYPE, MAP); generator.writeNumberField(KEY_ID, map.keyId()); generator.writeFieldName(KEY); toJson(map.keyType(), generator); generator.writeNumberField(VALUE_ID, map.valueId()); generator.writeFieldName(VALUE); toJson(map.valueType(), generator); generator.writeBooleanField(VALUE_REQUIRED, !map.isValueOptional()); generator.writeEndObject(); }
Example 4
Source File: JSonBindingUtils.java From roboconf-platform with Apache License 2.0 | 6 votes |
@Override public void serialize( WebSocketMessage wsm, JsonGenerator generator, SerializerProvider provider ) throws IOException { generator.writeStartObject(); if( wsm.getEventType() != null ) generator.writeStringField( WS_EVENT, wsm.getEventType().toString()); if( wsm.getApplication() != null ) generator.writeObjectField( WS_APP, wsm.getApplication()); if( wsm.getApplicationTemplate() != null ) generator.writeObjectField( WS_TPL, wsm.getApplicationTemplate()); if( wsm.getInstance() != null ) generator.writeObjectField( WS_INST, wsm.getInstance()); if( wsm.getMessage() != null ) generator.writeObjectField( WS_MSG, wsm.getMessage()); generator.writeEndObject(); }
Example 5
Source File: ODataErrorSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void writeODataError(final JsonGenerator json, final String code, final String message, final String target) throws IOException { json.writeFieldName(Constants.ERROR_CODE); if (code == null) { json.writeNull(); } else { json.writeString(code); } json.writeFieldName(Constants.ERROR_MESSAGE); if (message == null) { json.writeNull(); } else { json.writeString(message); } if (target != null) { json.writeStringField(Constants.ERROR_TARGET, target); } }
Example 6
Source File: OpenRtbJsonWriter.java From openrtb with Apache License 2.0 | 5 votes |
protected void writeDealFields(Deal deal, JsonGenerator gen) throws IOException { gen.writeStringField("id", deal.getId()); if (deal.hasBidfloor()) { gen.writeNumberField("bidfloor", deal.getBidfloor()); } if (deal.hasBidfloorcur()) { gen.writeStringField("bidfloorcur", deal.getBidfloorcur()); } writeStrings("wseat", deal.getWseatList(), gen); writeStrings("wadomain", deal.getWadomainList(), gen); if (deal.hasAt()) { writeEnumField("at", deal.getAt(), gen); } }
Example 7
Source File: SchemaParser.java From iceberg with Apache License 2.0 | 5 votes |
static void toJson(Types.ListType list, JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeStringField(TYPE, LIST); generator.writeNumberField(ELEMENT_ID, list.elementId()); generator.writeFieldName(ELEMENT); toJson(list.elementType(), generator); generator.writeBooleanField(ELEMENT_REQUIRED, !list.isElementOptional()); generator.writeEndObject(); }
Example 8
Source File: CountryTable.java From kripton with Apache License 2.0 | 5 votes |
/** * for attribute translatedName serialization */ public static byte[] serializeTranslatedName(Map<Translation, String> value) { if (value==null) { return null; } KriptonJsonContext context=KriptonBinder.jsonBind(); try (KriptonByteArrayOutputStream stream=new KriptonByteArrayOutputStream(); JacksonWrapperSerializer wrapper=context.createSerializer(stream)) { JsonGenerator jacksonSerializer=wrapper.jacksonGenerator; jacksonSerializer.writeStartObject(); int fieldCount=0; if (value!=null) { fieldCount++; // write wrapper tag if (value.size()>0) { jacksonSerializer.writeFieldName("element"); jacksonSerializer.writeStartArray(); for (Map.Entry<Translation, String> item: value.entrySet()) { jacksonSerializer.writeStartObject(); jacksonSerializer.writeStringField("key", item.getKey().toString()); if (item.getValue()==null) { jacksonSerializer.writeNullField("value"); } else { jacksonSerializer.writeStringField("value", item.getValue()); } jacksonSerializer.writeEndObject(); } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeNullField("element"); } } jacksonSerializer.writeEndObject(); jacksonSerializer.flush(); return stream.toByteArray(); } catch(Exception e) { e.printStackTrace(); throw(new KriptonRuntimeException(e.getMessage())); } }
Example 9
Source File: PersonBindMap.java From kripton with Apache License 2.0 | 5 votes |
@Override public int serializeOnJacksonAsString(Person object, JsonGenerator jacksonSerializer) throws Exception { jacksonSerializer.writeStartObject(); int fieldCount=0; // Serialized Field: // field birthCity (mapped with "birthCity") if (object.birthCity!=null) { fieldCount++; jacksonSerializer.writeStringField("birthCity", object.birthCity); } // field birthDay (mapped with "birthDay") if (object.birthDay!=null) { fieldCount++; jacksonSerializer.writeStringField("birthDay", DateUtils.write(object.birthDay)); } // field id (mapped with "id") jacksonSerializer.writeStringField("id", PrimitiveUtils.writeLong(object.id)); // field name (mapped with "name") if (object.name!=null) { fieldCount++; jacksonSerializer.writeStringField("name", object.name); } // field surname (mapped with "surname") if (object.surname!=null) { fieldCount++; jacksonSerializer.writeStringField("surname", object.surname); } jacksonSerializer.writeEndObject(); return fieldCount; }
Example 10
Source File: ImpExtWriter.java From openrtb-doubleclick with Apache License 2.0 | 5 votes |
@Override protected void write(ImpExt ext, JsonGenerator gen) throws IOException { writeLongs("billing_id", ext.getBillingIdList(), gen); writeLongs("publisher_settings_list_id", ext.getPublisherSettingsListIdList(), gen); writeInts("allowed_vendor_type", ext.getAllowedVendorTypeList(), gen); writeStrings("publisher_parameter", ext.getPublisherParameterList(), gen); if (ext.hasDfpAdUnitCode()) { gen.writeStringField("dfp_ad_unit_code", ext.getDfpAdUnitCode()); } if (ext.hasIsRewardedInventory()) { writeIntBoolField("is_rewarded_inventory", ext.getIsRewardedInventory(), gen); } if (ext.hasAmpad()) { writeEnumField("ampad", ext.getAmpad(), gen); } if (ext.getBuyerGeneratedRequestDataCount() != 0) { gen.writeArrayFieldStart("buyer_generated_request_data"); for (BuyerGeneratedRequestData feedback : ext.getBuyerGeneratedRequestDataList()) { writeBuyerGeneratedRequestData(feedback, gen); } gen.writeEndArray(); } if (ext.getExcludedCreativesCount() != 0) { gen.writeArrayFieldStart("excluded_creatives"); for (ExcludedCreative exCreat : ext.getExcludedCreativesList()) { writeExcludedCreative(exCreat, gen); } gen.writeEndArray(); } if (ext.hasOpenBidding()) { gen.writeFieldName("open_bidding"); writeOpenBidding(ext.getOpenBidding(), gen); } writeInts("allowed_restricted_category", ext.getAllowedRestrictedCategoryList(), gen); }
Example 11
Source File: ThriftJacksonSerializers.java From armeria with Apache License 2.0 | 5 votes |
static void serializeTMessage(TMessage value, JsonGenerator gen) throws IOException { gen.writeStartObject(); gen.writeStringField("name", value.name); gen.writeNumberField("type", value.type); gen.writeNumberField("seqid", value.seqid); gen.writeEndObject(); }
Example 12
Source File: HardwareAddressSerializer.java From c2mon with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void serialize(HardwareAddress hardwareAddress, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("xmlData", hardwareAddress.toConfigXML()); jsonGenerator.writeEndObject(); }
Example 13
Source File: PhoneNumberBindMap.java From kripton with Apache License 2.0 | 4 votes |
@Override public int serializeOnJackson(PhoneNumber object, JsonGenerator jacksonSerializer) throws Exception { jacksonSerializer.writeStartObject(); int fieldCount=0; // Serialized Field: // field actionType (mapped with "actionType") if (object.actionType!=null) { fieldCount++; jacksonSerializer.writeStringField("actionType", object.actionType.toString()); } // field contactId (mapped with "contactId") if (object.contactId!=null) { fieldCount++; jacksonSerializer.writeStringField("contactId", object.contactId); } // field contactName (mapped with "contactName") if (object.contactName!=null) { fieldCount++; jacksonSerializer.writeStringField("contactName", object.contactName); } // field countryCode (mapped with "countryCode") if (object.countryCode!=null) { fieldCount++; jacksonSerializer.writeStringField("countryCode", object.countryCode); } // field id (mapped with "id") fieldCount++; jacksonSerializer.writeNumberField("id", object.id); // field number (mapped with "number") if (object.number!=null) { fieldCount++; jacksonSerializer.writeStringField("number", object.number); } jacksonSerializer.writeEndObject(); return fieldCount; }
Example 14
Source File: DefaultDimensionSpec.java From Quicksql with MIT License | 4 votes |
@Override public void write(JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeStringField("type", "default"); generator.writeStringField("dimension", dimension); generator.writeEndObject(); }
Example 15
Source File: GraphJsonWriter.java From constellation with Apache License 2.0 | 4 votes |
/** * Serialise a graph in JSON format to an OutputStream. * <p> * The graph elements are written in the order GRAPH, VERTEX, TRANSACTION, * META. Each element type will be written, even if there are no elements of * that type. * <p> * Ancillary files are not written: only the JSON is done here. * <p> * Originally, the vertices were written to JSON using the position as the * id, so vx_id_ = 0, 1, 2, ... . This required everything else (in * particular the transaction writing code, but also implementers of * AbstractGraphIOProvider.writeObject()) to know about the mapping from * graph vertex id to JSON vertex id. Then I realised that is was much * easier to write the actual vertex id to JSON, because it doesn't matter * what the numbers are in the file, and since the file and JSON ids are the * same, there's no need to keep a mapping. * * @param graph The graph to serialise. * @param out The OutputStream to write to. * @param verbose Determines whether to write default values of attributes * or not. * @param elementTypes The GraphElementTypes to serialise. * * @return True if the user cancelled the write, false otherwise. * * @throws IOException If an I/O error occurs. */ public boolean writeGraphToStream(final GraphReadMethods graph, final OutputStream out, final boolean verbose, final List<GraphElementType> elementTypes) throws IOException { // Get a new JSON writer. // Don't close the underlying zip stream automatically. final JsonGenerator jg = new JsonFactory().createGenerator(out, JsonEncoding.UTF8); jg.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); jg.useDefaultPrettyPrinter(); counter = 0; isCancelled = false; try { final int total = graph.getVertexCount() + graph.getTransactionCount(); if (progress != null) { progress.start(total); } jg.writeStartArray(); jg.writeStartObject(); //write version number jg.writeNumberField("version", VERSION); //write versioned items jg.writeObjectFieldStart("versionedItems"); for (Entry<String, Integer> itemVersion : UpdateProviderManager.getLatestVersions().entrySet()) { jg.writeNumberField(itemVersion.getKey(), itemVersion.getValue()); } jg.writeEndObject(); Schema schema = graph.getSchema(); //write schema jg.writeStringField("schema", schema == null ? new BareSchemaFactory().getName() : schema.getFactory().getName()); //write global modCounts final long globalModCount = graph.getGlobalModificationCounter(); final long structModCount = graph.getStructureModificationCounter(); final long attrModCount = graph.getStructureModificationCounter(); jg.writeNumberField("global_mod_count", globalModCount); jg.writeNumberField("structure_mod_count", structModCount); jg.writeNumberField("attribute_mod_count", attrModCount); jg.writeEndObject(); for (GraphElementType elementType : ELEMENT_TYPES_FILE_ORDER) { if (!isCancelled) { writeElements(jg, graph, elementType, verbose, elementTypes.contains(elementType)); } } jg.writeEndArray(); } catch (Exception ex) { Exceptions.printStackTrace(ex); } finally { jg.close(); if (progress != null) { progress.finish(); } } return isCancelled; }
Example 16
Source File: SearchBindMap.java From kripton with Apache License 2.0 | 4 votes |
@Override public int serializeOnJacksonAsString(Search object, JsonGenerator jacksonSerializer) throws Exception { jacksonSerializer.writeStartObject(); int fieldCount=0; // Serialized Field: // field response (mapped with "response") if (object.getResponse()!=null) { fieldCount++; jacksonSerializer.writeStringField("response", object.getResponse()); } // field search (mapped with "search") if (object.getSearch()!=null) { fieldCount++; int n=object.getSearch().size(); Film item; // write wrapper tag jacksonSerializer.writeFieldName("search"); if (n>0) { jacksonSerializer.writeStartArray(); for (int i=0; i<n; i++) { item=object.getSearch().get(i); if (item==null) { jacksonSerializer.writeString("null"); } else { if (filmBindMap.serializeOnJacksonAsString(item, jacksonSerializer)==0) { jacksonSerializer.writeNullField("search"); } } } jacksonSerializer.writeEndArray(); } else { jacksonSerializer.writeString(""); } } // field totalResults (mapped with "totalResults") if (object.getTotalResults()!=null) { fieldCount++; jacksonSerializer.writeStringField("totalResults", object.getTotalResults()); } jacksonSerializer.writeEndObject(); return fieldCount; }
Example 17
Source File: TestTableMetadataJson.java From iceberg with Apache License 2.0 | 4 votes |
public static String toJsonWithoutSpecList(TableMetadata metadata) { StringWriter writer = new StringWriter(); try { JsonGenerator generator = JsonUtil.factory().createGenerator(writer); generator.writeStartObject(); // start table metadata object generator.writeNumberField(FORMAT_VERSION, TableMetadata.TABLE_FORMAT_VERSION); generator.writeStringField(LOCATION, metadata.location()); generator.writeNumberField(LAST_UPDATED_MILLIS, metadata.lastUpdatedMillis()); generator.writeNumberField(LAST_COLUMN_ID, metadata.lastColumnId()); generator.writeFieldName(SCHEMA); SchemaParser.toJson(metadata.schema(), generator); // mimic an old writer by writing only partition-spec and not the default ID or spec list generator.writeFieldName(PARTITION_SPEC); PartitionSpecParser.toJsonFields(metadata.spec(), generator); generator.writeObjectFieldStart(PROPERTIES); for (Map.Entry<String, String> keyValue : metadata.properties().entrySet()) { generator.writeStringField(keyValue.getKey(), keyValue.getValue()); } generator.writeEndObject(); generator.writeNumberField(CURRENT_SNAPSHOT_ID, metadata.currentSnapshot() != null ? metadata.currentSnapshot().snapshotId() : -1); generator.writeArrayFieldStart(SNAPSHOTS); for (Snapshot snapshot : metadata.snapshots()) { SnapshotParser.toJson(snapshot, generator); } generator.writeEndArray(); // skip the snapshot log generator.writeEndObject(); // end table metadata object generator.flush(); } catch (IOException e) { throw new RuntimeIOException(e, "Failed to write json for: %s", metadata); } return writer.toString(); }
Example 18
Source File: RntbdRequestRecord.java From azure-cosmosdb-java with MIT License | 4 votes |
@Override public void serialize( final RntbdRequestRecord value, final JsonGenerator generator, final SerializerProvider provider) throws IOException { generator.writeStartObject(); generator.writeObjectField("args", value.args()); generator.writeNumberField("requestLength", value.requestLength()); generator.writeNumberField("responseLength", value.responseLength()); // status generator.writeObjectFieldStart("status"); generator.writeBooleanField("done", value.isDone()); generator.writeBooleanField("cancelled", value.isCancelled()); generator.writeBooleanField("completedExceptionally", value.isCompletedExceptionally()); if (value.isCompletedExceptionally()) { try { value.get(); } catch (final ExecutionException executionException) { final Throwable error = executionException.getCause(); generator.writeObjectFieldStart("error"); generator.writeStringField("type", error.getClass().getName()); generator.writeObjectField("value", error); generator.writeEndObject(); } catch (CancellationException | InterruptedException exception) { generator.writeObjectFieldStart("error"); generator.writeStringField("type", exception.getClass().getName()); generator.writeObjectField("value", exception); generator.writeEndObject(); } } generator.writeEndObject(); generator.writeObjectField("timeline", value.takeTimelineSnapshot()); generator.writeEndObject(); }
Example 19
Source File: DruidQuery.java From Quicksql with MIT License | 4 votes |
public void write(JsonGenerator generator) throws IOException { generator.writeStartObject(); generator.writeStringField("type", type); generator.writeStringField("name", name); }
Example 20
Source File: FolderSerializerWithDefaultSerializerStored.java From tutorials with MIT License | 3 votes |
@Override public void serialize(Folder value, JsonGenerator gen, SerializerProvider provider) throws IOException { gen.writeStartObject(); gen.writeStringField("name", value.getName()); provider.defaultSerializeField("files", value.getFiles(), gen); gen.writeFieldName("details"); defaultSerializer.serialize(value, gen, provider); gen.writeEndObject(); }