Java Code Examples for com.fasterxml.jackson.core.JsonGenerator#writeArrayFieldStart()
The following examples show how to use
com.fasterxml.jackson.core.JsonGenerator#writeArrayFieldStart() .
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: GenerateIndexConfig.java From java-client-api with Apache License 2.0 | 6 votes |
private static void generatePathIndexes(List<PathIndexFound> paths, JsonGenerator config) throws IOException { config.writeArrayFieldStart("range-path-index"); for ( PathIndexFound found : paths ) { //System.err.println("found " + found.propertyName + " " + found.foundMessage); config.writeStartObject(); config.writeStringField("path-expression", found.getPath()); config.writeStringField("scalar-type", "" + found.scalarType.toString()); if ( PathIndexProperty.ScalarType.STRING == found.scalarType ) { config.writeStringField("collation", "http://marklogic.com/collation/"); // TODO: remove this else clause once https://bugtrack.marklogic.com/30043 is fixed } else { config.writeStringField("collation", ""); } config.writeStringField("range-value-positions", "false"); config.writeStringField("invalid-values", "ignore"); config.writeEndObject(); } config.writeEndArray(); }
Example 2
Source File: ODataErrorSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") private void writeODataAdditionalProperties(JsonGenerator json, Map<String, Object> additionalProperties) throws IOException { if (additionalProperties != null) { for (Entry<String, Object> additionalProperty : additionalProperties.entrySet()) { Object value = additionalProperty.getValue(); if (value instanceof List) { List<Map<String, Object>> list = (List<Map<String, Object>>) value; json.writeArrayFieldStart(additionalProperty.getKey()); for (Map<String, Object> entry : list) { json.writeStartObject(); writeODataAdditionalProperties(json, entry); json.writeEndObject(); } json.writeEndArray(); } else if (value instanceof Map) { writeODataAdditionalProperties(json, (Map<String, Object>) value); } else { json.writeObjectField(additionalProperty.getKey(), value); } } } }
Example 3
Source File: GenerateIndexConfig.java From java-client-api with Apache License 2.0 | 6 votes |
private static void generateGeoPairIndexes(List<GeoPairFound> geoPairs, JsonGenerator config) throws IOException { config.writeArrayFieldStart("geospatial-element-pair-index"); for ( GeoPairFound found : geoPairs ) { config.writeStartObject(); config.writeStringField("parent-namespace-uri", ""); config.writeStringField("parent-localname", found.fullyQualifiedClassName); //System.err.println("found " + found.latitudeName + " " + found.latitudeFoundMessage); config.writeStringField("latitude-namespace-uri", ""); config.writeStringField("latitude-localname", found.latitudeName); //System.err.println("found " + found.longitudeName + " " + found.longitudeFoundMessage); config.writeStringField("longitude-namespace-uri", ""); config.writeStringField("longitude-localname", found.longitudeName); config.writeStringField("coordinate-system", "wgs84"); config.writeStringField("range-value-positions", "false"); config.writeStringField("invalid-values", "ignore"); config.writeEndObject(); } config.writeEndArray(); }
Example 4
Source File: PerspectiveIOProvider.java From constellation with Apache License 2.0 | 6 votes |
@Override public void writeObject(final Attribute attribute, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException { if (verbose || !graph.isDefaultValue(attribute.getId(), elementId)) { final PerspectiveModel model = (PerspectiveModel) graph.getObjectValue(attribute.getId(), elementId); if (model == null) { jsonGenerator.writeNullField(attribute.getName()); } else { jsonGenerator.writeObjectFieldStart(attribute.getName()); jsonGenerator.writeArrayFieldStart(LIST); for (final Perspective p : model.perspectives) { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(LABEL, p.label); jsonGenerator.writeNumberField(RELATIVE_TO, p.relativeTo); writeVector(jsonGenerator, EYE, p.eye); writeVector(jsonGenerator, CENTRE, p.centre); writeVector(jsonGenerator, UP, p.up); writeVector(jsonGenerator, ROTATE, p.rotate); jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); jsonGenerator.writeEndObject(); } } }
Example 5
Source File: MetadataDocumentJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void appendKey(final JsonGenerator json, final EdmEntityType entityType) throws SerializerException, IOException { List<EdmKeyPropertyRef> keyPropertyRefs = entityType.getKeyPropertyRefs(); if (keyPropertyRefs != null && !keyPropertyRefs.isEmpty()) { // Resolve Base Type key as it is shown in derived type EdmEntityType baseType = entityType.getBaseType(); if (baseType != null && baseType.getKeyPropertyRefs() != null && !(baseType.getKeyPropertyRefs().isEmpty())) { return; } json.writeArrayFieldStart(KEY); for (EdmKeyPropertyRef keyRef : keyPropertyRefs) { if (keyRef.getAlias() != null) { json.writeStartObject(); json.writeStringField(keyRef.getAlias(), keyRef.getName()); json.writeEndObject(); } else { json.writeString(keyRef.getName()); } } json.writeEndArray(); } }
Example 6
Source File: CoordinatedClusterSerializer.java From usergrid with Apache License 2.0 | 6 votes |
@Override public void serialize( final ICoordinatedCluster value, final JsonGenerator jgen, final SerializerProvider provider ) throws IOException { jgen.writeStartObject(); jgen.writeStringField( NAME, value.getName() ); jgen.writeNumberField( SIZE, value.getSize() ); jgen.writeObjectField( INSTANCE_SPEC, value.getInstanceSpec() ); jgen.writeArrayFieldStart( INSTANCES ); for( Instance instance: value.getInstances() ) { jgen.writeObject( instance ); } jgen.writeEndArray(); jgen.writeEndObject(); }
Example 7
Source File: PlaneStateIOProvider.java From constellation with Apache License 2.0 | 6 votes |
@Override public void writeObject(final Attribute attr, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException { if (verbose || !graph.isDefaultValue(attr.getId(), elementId)) { final PlaneState state = (PlaneState) graph.getObjectValue(attr.getId(), elementId); if (state == null) { jsonGenerator.writeNullField(attr.getName()); } else { jsonGenerator.writeObjectFieldStart(attr.getName()); jsonGenerator.writeArrayFieldStart(PLANE_LIST); for (final Plane p : state.getPlanes()) { jsonGenerator.writeStartObject(); p.writeNode(jsonGenerator, byteWriter); jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); jsonGenerator.writeEndObject(); } } }
Example 8
Source File: VertexGraphLabelsIOProvider.java From constellation with Apache License 2.0 | 6 votes |
@Override public void writeObject(final Attribute attr, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException { if (verbose || !graph.isDefaultValue(attr.getId(), elementId)) { final GraphLabels graphLabels = graph.getObjectValue(attr.getId(), elementId); if (graphLabels == null) { jsonGenerator.writeNullField(attr.getName()); } else { jsonGenerator.writeArrayFieldStart(attr.getName()); for (GraphLabel graphLabel : graphLabels.getLabels()) { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField(ATTRIBUTE_NAME, graphLabel.getAttributeName()); final ConstellationColor color = graphLabel.getColor(); jsonGenerator.writeObjectFieldStart(COLOR); ColorIOProvider.writeColorObject(color, jsonGenerator); jsonGenerator.writeEndObject(); jsonGenerator.writeNumberField(RADIUS, graphLabel.getSize()); jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); } } }
Example 9
Source File: MetadataDocumentJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 6 votes |
private void appendIncludeAnnotations(JsonGenerator json, List<EdmxReferenceIncludeAnnotation> includeAnnotations) throws SerializerException, IOException { json.writeArrayFieldStart(INCLUDE_ANNOTATIONS); for (EdmxReferenceIncludeAnnotation includeAnnotation : includeAnnotations) { json.writeStartObject(); json.writeStringField(TERM_NAMESPACE, includeAnnotation.getTermNamespace()); if (includeAnnotation.getQualifier() != null) { json.writeStringField(QUALIFIER, includeAnnotation.getQualifier()); } if (includeAnnotation.getTargetNamespace() != null) { json.writeStringField(TARGET_NAMESPACE, includeAnnotation.getTargetNamespace()); } json.writeEndObject(); } json.writeEndArray(); }
Example 10
Source File: ResourceEncoder.java From agrest with Apache License 2.0 | 5 votes |
private void writeOperations(Collection<AgOperation> operations, JsonGenerator out) throws IOException { out.writeArrayFieldStart("operations"); // sort operations for encoding consistency Collection<AgOperation> sorted = operations.size() > 1 ? operations.stream().sorted(comparing(op -> op.getMethod().name())).collect(toList()) : operations; for (AgOperation operation : sorted) { out.writeStartObject(); out.writeStringField("method", operation.getMethod().name()); out.writeEndObject(); } out.writeEndArray(); }
Example 11
Source File: BaseSerializer.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
/** * Helper used to help serialize a list of strings. * * @param jgen The json generator to use. * @param fieldname The name to associated to the resulting json array. * @param values The values to populate the array with. * @throws IOException If an error occurs while writing to the generator. */ protected void writeStringArray(JsonGenerator jgen, String fieldname, Collection<String> values) throws IOException { jgen.writeArrayFieldStart(fieldname); for (String nextElement : values) { jgen.writeString(nextElement); } jgen.writeEndArray(); }
Example 12
Source File: JsonServiceDocumentWriter.java From odata with Apache License 2.0 | 5 votes |
/** * The main method for Writer. * 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); } }
Example 13
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 14
Source File: OpenRtbJsonWriter.java From openrtb with Apache License 2.0 | 5 votes |
protected void writeDataFields(Data data, JsonGenerator gen) throws IOException { if (data.hasId()) { gen.writeStringField("id", data.getId()); } if (data.hasName()) { gen.writeStringField("name", data.getName()); } if (data.getSegmentCount() != 0) { gen.writeArrayFieldStart("segment"); for (Segment segment : data.getSegmentList()) { writeSegment(segment, gen); } gen.writeEndArray(); } }
Example 15
Source File: OpenRtbJsonWriter.java From openrtb with Apache License 2.0 | 5 votes |
protected void writeUserFields(User user, JsonGenerator gen) throws IOException { if (user.hasId()) { gen.writeStringField("id", user.getId()); } if (user.hasBuyeruid()) { gen.writeStringField("buyeruid", user.getBuyeruid()); } if (user.hasYob()) { gen.writeNumberField("yob", user.getYob()); } if (user.hasGender() && Gender.forCode(user.getGender()) != null) { gen.writeStringField("gender", user.getGender()); } if (user.hasKeywords()) { gen.writeStringField("keywords", user.getKeywords()); } if (user.hasCustomdata()) { gen.writeStringField("customdata", user.getCustomdata()); } if (user.hasGeo()) { gen.writeFieldName("geo"); writeGeo(user.getGeo(), gen); } if (user.getDataCount() != 0) { gen.writeArrayFieldStart("data"); for (Data data : user.getDataList()) { writeData(data, gen); } gen.writeEndArray(); } }
Example 16
Source File: AbstractOpenRtbJsonWriter.java From openrtb with Apache License 2.0 | 5 votes |
/** * Writes an array of ContentCategory if not empty. * * @see #writeContentCategory(String, JsonGenerator) */ protected final void writeContentCategories( String fieldName, List<String> cats, JsonGenerator gen) throws IOException { if (!cats.isEmpty()) { gen.writeArrayFieldStart(fieldName); for (String cat : cats) { writeContentCategory(cat, gen); } gen.writeEndArray(); } }
Example 17
Source File: ApplicationAgentHostListSerializer.java From pinpoint with Apache License 2.0 | 5 votes |
private void writeApplication(String applicationName, List<AgentInfo> agentInfoList, JsonGenerator jsonGenerator) throws IOException { jsonGenerator.writeStringField("applicationName", applicationName); jsonGenerator.writeArrayFieldStart("agents"); writeAgentList(agentInfoList, jsonGenerator); jsonGenerator.writeEndArray(); }
Example 18
Source File: ListTablesResponseSerDe.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
@Override protected void doTypedSerialize(FederationResponse federationResponse, JsonGenerator jgen, SerializerProvider provider) throws IOException { ListTablesResponse listTablesResponse = (ListTablesResponse) federationResponse; jgen.writeArrayFieldStart(TABLES_FIELD); for (TableName tableName : listTablesResponse.getTables()) { tableNameSerializer.serialize(tableName, jgen, provider); } jgen.writeEndArray(); jgen.writeStringField(CATALOG_NAME_FIELD, listTablesResponse.getCatalogName()); }
Example 19
Source File: ReplicaLocation.java From pegasus with Apache License 2.0 | 5 votes |
/** * Serializes contents into YAML representation Sample representation below * * <pre> * lfn: "f2" * pfns: * - * pfn: "file:///path/to/file" * site: "local" * - * pfn: "file:///path/to/file" * site: "condorpool" * checksum: * sha256: "991232132abc" * metadata: * owner: "pegasus" * abc: "123" * size: "1024" * k: "v" * </pre> * * @param r; * @param gen * @param sp * @throws IOException */ public void serialize(ReplicaLocation rl, JsonGenerator gen, SerializerProvider sp) throws IOException { gen.writeStartObject(); writeStringField(gen, ReplicaCatalogKeywords.LFN.getReservedName(), rl.getLFN()); if (rl.isRegex()) { writeStringField(gen, ReplicaCatalogKeywords.REGEX.getReservedName(), "true"); } if (rl.getPFNCount() > 0) { gen.writeArrayFieldStart(ReplicaCatalogKeywords.PFNS.getReservedName()); for (ReplicaCatalogEntry rce : rl.getPFNList()) { gen.writeStartObject(); // we don't quote or escape anything as serializer // always adds enclosing quotes writeStringField( gen, ReplicaCatalogKeywords.PFN.getReservedName(), rce.getPFN()); writeStringField( gen, ReplicaCatalogKeywords.SITE.getReservedName(), rce.getResourceHandle()); gen.writeEndObject(); } gen.writeEndArray(); } Metadata m = rl.getAllMetadata(); if (m != null && !m.isEmpty()) { gen.writeObject(m); } gen.writeEndObject(); }
Example 20
Source File: OpenRtbJsonExtWriter.java From openrtb with Apache License 2.0 | 5 votes |
protected final void writeRepeated(List<T> extList, JsonGenerator gen) throws IOException { gen.writeArrayFieldStart(rootName); for (T ext : extList) { if (isJsonObject) { gen.writeStartObject(); } write(ext, gen); if (isJsonObject) { gen.writeEndObject(); } } gen.writeEndArray(); }