Java Code Examples for com.fasterxml.jackson.core.JsonGenerator#writeObjectFieldStart()
The following examples show how to use
com.fasterxml.jackson.core.JsonGenerator#writeObjectFieldStart() .
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: 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 2
Source File: MetricsElasticsearchModule.java From oneops with Apache License 2.0 | 5 votes |
@Override public void serialize(BulkIndexOperationHeader bulkIndexOperationHeader, JsonGenerator json, SerializerProvider provider) throws IOException { json.writeStartObject(); json.writeObjectFieldStart("index"); if (bulkIndexOperationHeader.index != null) { json.writeStringField("_index", bulkIndexOperationHeader.index); } if (bulkIndexOperationHeader.type != null) { json.writeStringField("_type", bulkIndexOperationHeader.type); } json.writeEndObject(); json.writeEndObject(); }
Example 3
Source File: RDFJSONWriter.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void modelToRdfJsonInternal(final Model graph, final WriterConfig writerConfig, final JsonGenerator jg) throws IOException, JsonGenerationException { if (writerConfig.get(BasicWriterSettings.PRETTY_PRINT)) { // SES-2011: Always use \n for consistency Indenter indenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE; // By default Jackson does not pretty print, so enable this unless // PRETTY_PRINT setting is disabled DefaultPrettyPrinter pp = new DefaultPrettyPrinter().withArrayIndenter(indenter) .withObjectIndenter(indenter); jg.setPrettyPrinter(pp); } jg.writeStartObject(); for (final Resource nextSubject : graph.subjects()) { jg.writeObjectFieldStart(RDFJSONWriter.resourceToString(nextSubject)); for (final IRI nextPredicate : graph.filter(nextSubject, null, null).predicates()) { jg.writeArrayFieldStart(nextPredicate.stringValue()); for (final Value nextObject : graph.filter(nextSubject, nextPredicate, null).objects()) { // contexts are optional, so this may return empty in some // scenarios depending on the interpretation of the way contexts // work final Set<Resource> contexts = graph.filter(nextSubject, nextPredicate, nextObject).contexts(); RDFJSONWriter.writeObject(nextObject, contexts, jg); } jg.writeEndArray(); } jg.writeEndObject(); } jg.writeEndObject(); }
Example 4
Source File: ASTSignatureChangeSerializer.java From steady with Apache License 2.0 | 5 votes |
/** * Helper method for building a "SourceCodeEntity" element * * @param change - SourcCodeChangeElement * @param buffer */ private void writeSourceCodeEntityElement(JsonGenerator jgen, String _property_name, SourceCodeEntity _entity) throws IOException { jgen.writeObjectFieldStart(_property_name); jgen.writeStringField("UniqueName", _entity.getUniqueName().toString()); jgen.writeStringField("EntityType", _entity.getType().toString()); jgen.writeStringField("Modifiers", new Integer(_entity.getModifiers()).toString()); jgen.writeObjectFieldStart("SourceCodeRange"); jgen.writeStringField("Start", new Integer(_entity.getSourceRange().getStart()).toString()); jgen.writeStringField("End", new Integer(_entity.getSourceRange().getEnd()).toString()); jgen.writeEndObject(); jgen.writeEndObject(); }
Example 5
Source File: TransactionTypeIOProvider.java From constellation with Apache License 2.0 | 5 votes |
private static void writeTypeObject(final SchemaTransactionType type, final JsonGenerator jsonGenerator) throws IOException { jsonGenerator.writeStringField(NAME_FIELD, type.getName()); if (type.getDescription() != null) { jsonGenerator.writeStringField(DESCRIPTION_FIELD, type.getDescription()); } if (type.getColor() != null) { jsonGenerator.writeObjectFieldStart(COLOR_FIELD); writeColorObject(type.getColor(), jsonGenerator); jsonGenerator.writeEndObject(); } if (type.getStyle() != null) { jsonGenerator.writeStringField(STYLE_FIELD, type.getStyle().name()); } if (type.isDirected() != null) { jsonGenerator.writeBooleanField(DIRECTED_FIELD, type.isDirected()); } if (type.getSuperType() != null && type != type.getSuperType()) { jsonGenerator.writeObjectFieldStart(SUPERTYPE_FIELD); writeTypeObject((SchemaTransactionType) type.getSuperType(), jsonGenerator); jsonGenerator.writeEndObject(); } if (type.getOverridenType() != null && type != type.getOverridenType()) { jsonGenerator.writeObjectFieldStart(OVERRIDDEN_TYPE_FIELD); writeTypeObject((SchemaTransactionType) type.getOverridenType(), jsonGenerator); jsonGenerator.writeEndObject(); } if (type.getProperties() != null) { jsonGenerator.writeObjectFieldStart(PROPERTIES_FIELD); for (Entry<String, String> entry : type.getProperties().entrySet()) { jsonGenerator.writeStringField(entry.getKey(), entry.getValue() != null ? entry.getValue() : null); } jsonGenerator.writeEndObject(); } jsonGenerator.writeBooleanField(INCOMPLETE_FIELD, type.isIncomplete()); }
Example 6
Source File: MetadataDocumentJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void appendFunctionImports(final JsonGenerator json, final List<EdmFunctionImport> functionImports, final String containerNamespace) throws SerializerException, IOException { for (EdmFunctionImport functionImport : functionImports) { json.writeObjectFieldStart(functionImport.getName()); json.writeStringField(KIND, Kind.FunctionImport.name()); String functionFQNString; FullQualifiedName functionFqn = functionImport.getFunctionFqn(); if (namespaceToAlias.get(functionFqn.getNamespace()) != null) { functionFQNString = namespaceToAlias.get(functionFqn.getNamespace()) + "." + functionFqn.getName(); } else { functionFQNString = functionFqn.getFullQualifiedNameAsString(); } json.writeStringField(DOLLAR + Kind.Function.name(), functionFQNString); EdmEntitySet returnedEntitySet = functionImport.getReturnedEntitySet(); if (returnedEntitySet != null) { json.writeStringField(DOLLAR + Kind.EntitySet.name(), containerNamespace + "." + returnedEntitySet.getName()); } // Default is false and we do not write the default if (functionImport.isIncludeInServiceDocument()) { json.writeBooleanField(INCLUDE_IN_SERV_DOC, functionImport.isIncludeInServiceDocument()); } appendAnnotations(json, functionImport, null); json.writeEndObject(); } }
Example 7
Source File: TraceCommonService.java From glowroot with Apache License 2.0 | 5 votes |
private static void writeJson(Trace.Entry entry, JsonGenerator jg) throws IOException { jg.writeNumberField("startOffsetNanos", entry.getStartOffsetNanos()); jg.writeNumberField("durationNanos", entry.getDurationNanos()); if (entry.getActive()) { jg.writeBooleanField("active", true); } if (entry.hasQueryEntryMessage()) { jg.writeObjectFieldStart("queryMessage"); Trace.QueryEntryMessage queryMessage = entry.getQueryEntryMessage(); jg.writeNumberField("sharedQueryTextIndex", queryMessage.getSharedQueryTextIndex()); jg.writeStringField("prefix", queryMessage.getPrefix()); jg.writeStringField("suffix", queryMessage.getSuffix()); jg.writeEndObject(); } else { jg.writeStringField("message", entry.getMessage()); } List<Trace.DetailEntry> detailEntries = entry.getDetailEntryList(); if (!detailEntries.isEmpty()) { jg.writeFieldName("detail"); writeDetailEntries(detailEntries, jg); } List<Proto.StackTraceElement> locationStackTraceElements = entry.getLocationStackTraceElementList(); if (!locationStackTraceElements.isEmpty()) { jg.writeArrayFieldStart("locationStackTraceElements"); for (Proto.StackTraceElement stackTraceElement : locationStackTraceElements) { writeStackTraceElement(stackTraceElement, jg); } jg.writeEndArray(); } if (entry.hasError()) { jg.writeFieldName("error"); writeError(entry.getError(), jg); } }
Example 8
Source File: MetadataDocumentJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void appendSingletons(final JsonGenerator json, final List<EdmSingleton> singletons) throws SerializerException, IOException { for (EdmSingleton singleton : singletons) { json.writeObjectFieldStart(singleton.getName()); json.writeStringField(KIND, Kind.Singleton.name()); json.writeStringField(TYPE, getAliasedFullQualifiedName(singleton.getEntityType())); appendNavigationPropertyBindings(json, singleton); appendAnnotations(json, singleton, null); json.writeEndObject(); } }
Example 9
Source File: ErrorDataSerializer.java From katharsis-framework with Apache License 2.0 | 5 votes |
private static void writeAboutLink(ErrorData errorData, JsonGenerator gen) throws IOException { if (errorData.getAboutLink() != null) { gen.writeObjectFieldStart(LINKS); gen.writeStringField(ABOUT_LINK, errorData.getAboutLink()); gen.writeEndObject(); } }
Example 10
Source File: MetadataDocumentJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 5 votes |
private void appendAnnotationGroups(final JsonGenerator json, final List<EdmAnnotations> annotationGroups) throws SerializerException, IOException { if (!annotationGroups.isEmpty()) { json.writeObjectFieldStart(ANNOTATION); } for (EdmAnnotations annotationGroup : annotationGroups) { appendAnnotationGroup(json, annotationGroup); } if (!annotationGroups.isEmpty()) { json.writeEndObject(); } }
Example 11
Source File: CandlestickEventSerializer.java From zheshiyigeniubidexiangmu with MIT License | 5 votes |
@Override public void serialize(CandlestickEvent candlestickEvent, JsonGenerator gen, SerializerProvider serializers) throws IOException { gen.writeStartObject(); // Write header gen.writeStringField("e", candlestickEvent.getEventType()); gen.writeNumberField("E", candlestickEvent.getEventTime()); gen.writeStringField("s", candlestickEvent.getSymbol()); // Write candlestick data gen.writeObjectFieldStart("k"); gen.writeNumberField("t", candlestickEvent.getOpenTime()); gen.writeNumberField("T", candlestickEvent.getCloseTime()); gen.writeStringField("i", candlestickEvent.getIntervalId()); gen.writeNumberField("f", candlestickEvent.getFirstTradeId()); gen.writeNumberField("L", candlestickEvent.getLastTradeId()); gen.writeStringField("o", candlestickEvent.getOpen()); gen.writeStringField("c", candlestickEvent.getClose()); gen.writeStringField("h", candlestickEvent.getHigh()); gen.writeStringField("l", candlestickEvent.getLow()); gen.writeStringField("v", candlestickEvent.getVolume()); gen.writeNumberField("n", candlestickEvent.getNumberOfTrades()); gen.writeBooleanField("x", candlestickEvent.getBarFinal()); gen.writeStringField("q", candlestickEvent.getQuoteAssetVolume()); gen.writeStringField("V", candlestickEvent.getTakerBuyBaseAssetVolume()); gen.writeStringField("Q", candlestickEvent.getTakerBuyQuoteAssetVolume()); gen.writeEndObject(); }
Example 12
Source File: TracingReporter.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Get the structured log message format * * @param timeStamp timeStamp Instant * @param span opentracing SpanData * @return structured log message format String * */ private String toStructuredMessage(Instant timeStamp, SpanData span) { try { StringWriter writer = new StringWriter(); JsonGenerator generator = this.jsonFactory.createGenerator(writer); generator.writeStartObject(); generator.writeNumberField(TracingConstants.LATENCY, Duration.between(span.startAt, timeStamp).toMillis()); generator.writeStringField(TracingConstants.OPERATION_NAME, span.operationName); generator.writeObjectFieldStart(TracingConstants.TAGS); Iterator itr = span.tags.entrySet().iterator(); Map.Entry map; Object value; while (itr.hasNext()) { map = (Map.Entry) itr.next(); value = map.getValue(); if (value instanceof String) { generator.writeStringField((String) map.getKey(), (String) value); } else if (value instanceof Number) { generator.writeNumberField((String) map.getKey(), ((Number) value).doubleValue()); } else if (value instanceof Boolean) { generator.writeBooleanField((String) map.getKey(), (Boolean) value); } } generator.writeEndObject(); generator.close(); writer.close(); return writer.toString(); } catch (IOException e) { log.error("Error in structured message" , e); return null; } }
Example 13
Source File: CameraIOProviderV0.java From constellation with Apache License 2.0 | 5 votes |
/** * Add a Frame to an ObjectNode. * * @param node The ObjectNode to write the Frame to. * @param label The label of the Frame node. * @param frame The Frame to be written. */ private static void addFrame(final JsonGenerator jg, final String label, final Frame frame) throws IOException { jg.writeObjectFieldStart(label); final Vector3f v = new Vector3f(); frame.getOrigin(v); addVector(jg, "origin", v); frame.getForwardVector(v); addVector(jg, "forward", v); frame.getUpVector(v); addVector(jg, "up", v); jg.writeEndObject(); }
Example 14
Source File: SnapshotParser.java From iceberg with Apache License 2.0 | 4 votes |
static void toJson(Snapshot snapshot, JsonGenerator generator) throws IOException { generator.writeStartObject(); if (snapshot.sequenceNumber() > TableMetadata.INITIAL_SEQUENCE_NUMBER) { generator.writeNumberField(SEQUENCE_NUMBER, snapshot.sequenceNumber()); } generator.writeNumberField(SNAPSHOT_ID, snapshot.snapshotId()); if (snapshot.parentId() != null) { generator.writeNumberField(PARENT_SNAPSHOT_ID, snapshot.parentId()); } generator.writeNumberField(TIMESTAMP_MS, snapshot.timestampMillis()); // if there is an operation, write the summary map if (snapshot.operation() != null) { generator.writeObjectFieldStart(SUMMARY); generator.writeStringField(OPERATION, snapshot.operation()); if (snapshot.summary() != null) { for (Map.Entry<String, String> entry : snapshot.summary().entrySet()) { // only write operation once if (OPERATION.equals(entry.getKey())) { continue; } generator.writeStringField(entry.getKey(), entry.getValue()); } } generator.writeEndObject(); } String manifestList = snapshot.manifestListLocation(); if (manifestList != null) { // write just the location. manifests should not be embedded in JSON along with a list generator.writeStringField(MANIFEST_LIST, manifestList); } else { // embed the manifest list in the JSON, v1 only generator.writeArrayFieldStart(MANIFESTS); for (ManifestFile file : snapshot.allManifests()) { generator.writeString(file.path()); } generator.writeEndArray(); } generator.writeEndObject(); }
Example 15
Source File: MetadataDocumentJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void appendConstantExpression(final JsonGenerator json, final EdmConstantExpression constExp, String termName) throws SerializerException, IOException { switch (constExp.getExpressionType()) { case Binary: json.writeObjectFieldStart(termName); json.writeStringField(DOLLAR + constExp.getExpressionName(), constExp.getValueAsString()); json.writeEndObject(); break; case Date: json.writeObjectFieldStart(termName); json.writeStringField(DOLLAR + constExp.getExpressionName(), constExp.getValueAsString()); json.writeEndObject(); break; case DateTimeOffset: json.writeObjectFieldStart(termName); json.writeStringField(DOLLAR + constExp.getExpressionName(), constExp.getValueAsString()); json.writeEndObject(); break; case Decimal: json.writeObjectFieldStart(termName); json.writeStringField(DOLLAR + constExp.getExpressionName(), constExp.getValueAsString()); json.writeEndObject(); break; case Float: json.writeObjectFieldStart(termName); json.writeStringField(DOLLAR + constExp.getExpressionName(), constExp.getValueAsString()); json.writeEndObject(); break; case Int: json.writeObjectFieldStart(termName); json.writeStringField(DOLLAR + constExp.getExpressionName(), constExp.getValueAsString()); json.writeEndObject(); break; case Duration: json.writeObjectFieldStart(termName); json.writeStringField(DOLLAR + constExp.getExpressionName(), constExp.getValueAsString()); json.writeEndObject(); break; case EnumMember: json.writeObjectFieldStart(termName); json.writeStringField(DOLLAR + constExp.getExpressionName(), constExp.getValueAsString()); json.writeEndObject(); break; case Guid: json.writeObjectFieldStart(termName); json.writeStringField("$" + constExp.getExpressionName(), constExp.getValueAsString()); json.writeEndObject(); break; case TimeOfDay: json.writeObjectFieldStart(termName); json.writeStringField(DOLLAR + constExp.getExpressionName(), constExp.getValueAsString()); json.writeEndObject(); break; case Bool: if (termName != null && termName.length() > 0) { json.writeBooleanField(termName, Boolean.valueOf(constExp.getValueAsString())); } else { json.writeBoolean(Boolean.valueOf(constExp.getValueAsString())); } break; case String: if (termName != null && termName.length() > 0) { json.writeStringField(termName, constExp.getValueAsString()); } else { json.writeString(constExp.getValueAsString()); } break; default: throw new IllegalArgumentException("Unkown ExpressionType " + "for constant expression: " + constExp.getExpressionType()); } }
Example 16
Source File: JSONDump.java From pysonar2 with Apache License 2.0 | 4 votes |
private static void writeSymJson(Binding binding, JsonGenerator json) throws IOException { if (binding.start < 0) { return; } String name = binding.name; boolean isExported = !( Binding.Kind.VARIABLE == binding.kind || Binding.Kind.PARAMETER == binding.kind || Binding.Kind.SCOPE == binding.kind || Binding.Kind.ATTRIBUTE == binding.kind || (name.length() == 0 || name.charAt(0) == '_' || name.startsWith("lambda%"))); String path = binding.qname.replace('.', '/').replace("%20", "."); if (!seenDef.contains(path)) { seenDef.add(path); json.writeStartObject(); json.writeStringField("name", name); json.writeStringField("path", path); json.writeStringField("file", binding.fileOrUrl); json.writeNumberField("identStart", binding.start); json.writeNumberField("identEnd", binding.end); json.writeNumberField("defStart", binding.bodyStart); json.writeNumberField("defEnd", binding.bodyEnd); json.writeBooleanField("exported", isExported); json.writeStringField("kind", binding.kind.toString()); if (Binding.Kind.FUNCTION == binding.kind || Binding.Kind.METHOD == binding.kind || Binding.Kind.CONSTRUCTOR == binding.kind) { json.writeObjectFieldStart("funcData"); // get args expression String argExpr = null; Type t = binding.type; if (t instanceof UnionType) { t = ((UnionType) t).firstUseful(); } if (t != null && t instanceof FunType) { FunctionDef func = ((FunType) t).func; if (func != null) { argExpr = func.getArgumentExpr(); } } String typeExpr = binding.type.toString(); json.writeNullField("params"); String signature = argExpr == null ? "" : argExpr + "\n" + typeExpr; json.writeStringField("signature", signature); json.writeEndObject(); } json.writeEndObject(); } }
Example 17
Source File: MetadataDocumentJsonSerializer.java From olingo-odata4 with Apache License 2.0 | 4 votes |
private void appendNavigationProperties(final JsonGenerator json, final EdmStructuredType type) throws SerializerException, IOException { List<String> navigationPropertyNames = new ArrayList<>(type.getNavigationPropertyNames()); if (type.getBaseType() != null) { navigationPropertyNames.removeAll(type.getBaseType().getNavigationPropertyNames()); } for (String navigationPropertyName : navigationPropertyNames) { EdmNavigationProperty navigationProperty = type.getNavigationProperty(navigationPropertyName); json.writeObjectFieldStart(navigationPropertyName); json.writeStringField(KIND, Kind.NavigationProperty.name()); json.writeStringField(TYPE, getAliasedFullQualifiedName(navigationProperty.getType())); if (navigationProperty.isCollection()) { json.writeBooleanField(COLLECTION, navigationProperty.isCollection()); } if (!navigationProperty.isNullable()) { json.writeBooleanField(NULLABLE, navigationProperty.isNullable()); } if (navigationProperty.getPartner() != null) { EdmNavigationProperty partner = navigationProperty.getPartner(); json.writeStringField(PARTNER, partner.getName()); } if (navigationProperty.containsTarget()) { json.writeBooleanField(CONTAINS_TARGET, navigationProperty.containsTarget()); } if (navigationProperty.getReferentialConstraints() != null) { for (EdmReferentialConstraint constraint : navigationProperty.getReferentialConstraints()) { json.writeObjectFieldStart(REFERENTIAL_CONSTRAINT); json.writeStringField(constraint.getPropertyName(), constraint.getReferencedPropertyName()); for (EdmAnnotation annotation : constraint.getAnnotations()) { appendAnnotations(json, annotation, null); } json.writeEndObject(); } } if (navigationProperty.getOnDelete() != null) { json.writeObjectFieldStart(ON_DELETE); json.writeStringField(ON_DELETE_PROPERTY, navigationProperty.getOnDelete().getAction()); appendAnnotations(json, navigationProperty.getOnDelete(), null); json.writeEndObject(); } appendAnnotations(json, navigationProperty, null); json.writeEndObject(); } }
Example 18
Source File: JsonSerializationHelper.java From vespa with Apache License 2.0 | 4 votes |
private static void serializeTensorAddress(JsonGenerator generator, TensorAddress address, TensorType type) throws IOException { generator.writeObjectFieldStart(TensorReader.TENSOR_ADDRESS); for (int i = 0; i < type.dimensions().size(); i++) generator.writeStringField(type.dimensions().get(i).name(), address.label(i)); generator.writeEndObject(); }
Example 19
Source File: VertexTypeIOProvider.java From constellation with Apache License 2.0 | 4 votes |
public static final void writeTypeObject(final SchemaVertexType type, final JsonGenerator jsonGenerator) throws IOException { jsonGenerator.writeStringField(NAME_FIELD, type.getName()); if (type.getDescription() != null) { jsonGenerator.writeStringField(DESCRIPTION_FIELD, type.getDescription()); } if (type.getColor() != null) { jsonGenerator.writeObjectFieldStart(COLOR_FIELD); writeColorObject(type.getColor(), jsonGenerator); jsonGenerator.writeEndObject(); } if (type.getForegroundIcon() != null) { jsonGenerator.writeStringField(FOREGROUND_ICON_FIELD, type.getForegroundIcon().getExtendedName()); } if (type.getBackgroundIcon() != null) { jsonGenerator.writeStringField(BACKGROUND_ICON_FIELD, type.getBackgroundIcon().getExtendedName()); } if (type.getDetectionRegex() != null) { jsonGenerator.writeStringField(DETECTION_REGEX_FIELD, type.getDetectionRegex().pattern()); } if (type.getValidationRegex() != null) { jsonGenerator.writeStringField(VALIDATION_REGEX_FIELD, type.getValidationRegex().pattern()); } if (type.getSuperType() != null && type != type.getSuperType()) { jsonGenerator.writeObjectFieldStart(SUPERTYPE_FIELD); writeTypeObject((SchemaVertexType) type.getSuperType(), jsonGenerator); jsonGenerator.writeEndObject(); } if (type.getOverridenType() != null && type != type.getOverridenType()) { jsonGenerator.writeObjectFieldStart(OVERRIDDEN_TYPE_FIELD); writeTypeObject((SchemaVertexType) type.getOverridenType(), jsonGenerator); jsonGenerator.writeEndObject(); } if (type.getProperties() != null) { jsonGenerator.writeObjectFieldStart(PROPERTIES_FIELD); for (Map.Entry<String, String> entry : type.getProperties().entrySet()) { jsonGenerator.writeStringField(entry.getKey(), entry.getValue() != null ? entry.getValue() : null); } jsonGenerator.writeEndObject(); } jsonGenerator.writeBooleanField(INCOMPLETE_FIELD, type.isIncomplete()); }
Example 20
Source File: Api1_15VersionSerializer.java From gravitee-management-rest-api with Apache License 2.0 | 4 votes |
@Override public void serialize(ApiEntity apiEntity, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { super.serialize(apiEntity, jsonGenerator, serializerProvider); // proxy part if (apiEntity.getProxy() != null) { jsonGenerator.writeObjectFieldStart("proxy"); // We assume that the API is containing a single virtual host Iterator<VirtualHost> virtualHostIterator = apiEntity.getProxy().getVirtualHosts().iterator(); if (virtualHostIterator.hasNext()) { jsonGenerator.writeObjectField("context_path", virtualHostIterator.next().getPath()); } jsonGenerator.writeObjectField("strip_context_path", apiEntity.getProxy().isStripContextPath()); if (apiEntity.getProxy().getLogging() == null) { jsonGenerator.writeObjectField("loggingMode", LoggingMode.NONE); } else { jsonGenerator.writeObjectField("loggingMode", apiEntity.getProxy().getLogging().getMode()); } jsonGenerator.writeObjectField("endpoints", apiEntity.getProxy().getGroups().stream() .map(endpointGroup -> endpointGroup.getEndpoints()) .flatMap(Collection::stream) .collect(Collectors.toList())); // load balancing (get load balancing of the first endpoints group) jsonGenerator.writeObjectField("load_balancing", apiEntity.getProxy().getGroups().iterator().next().getLoadBalancer()); if (apiEntity.getProxy().getFailover() != null) { jsonGenerator.writeObjectField("failover", apiEntity.getProxy().getFailover()); } if (apiEntity.getProxy().getCors() != null) { jsonGenerator.writeObjectField("cors", apiEntity.getProxy().getCors()); } jsonGenerator.writeEndObject(); } // handle filtered fields list List<String> filteredFieldsList = (List<String>) apiEntity.getMetadata().get(METADATA_FILTERED_FIELDS_LIST); // members if (!filteredFieldsList.contains("members")) { Set<MemberEntity> memberEntities = applicationContext.getBean(MembershipService.class).getMembersByReference(MembershipReferenceType.API, apiEntity.getId()); List<Member> members = (memberEntities == null ? Collections.emptyList() : new ArrayList<>(memberEntities.size())); if (memberEntities != null && !memberEntities.isEmpty()) { memberEntities.forEach(m -> { UserEntity userEntity = applicationContext.getBean(UserService.class).findById(m.getId()); if (userEntity != null) { Member member = new Member(); member.setUsername(getUsernameFromSourceId(userEntity.getSourceId())); member.setRole(m.getRoles().get(0).getName()); members.add(member); } }); } jsonGenerator.writeObjectField("members", members); } //plans if (!filteredFieldsList.contains("plans")) { Set<PlanEntity> plans = applicationContext.getBean(PlanService.class).findByApi(apiEntity.getId()); Set<PlanEntityBefore_3_00> plansToAdd = plans == null ? Collections.emptySet() : plans.stream() .filter(p -> !PlanStatus.CLOSED.equals(p.getStatus())) .map(PlanEntityBefore_3_00::fromNewPlanEntity) .collect(Collectors.toSet()); jsonGenerator.writeObjectField("plans", plansToAdd); } // must end the writing process jsonGenerator.writeEndObject(); }