com.fasterxml.jackson.core.JsonGenerator#writeObjectFieldStart ( )源码实例Demo

下面列出了com.fasterxml.jackson.core.JsonGenerator#writeObjectFieldStart ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: constellation   文件: PerspectiveIOProvider.java
@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();
        }
    }
}
 
源代码2 项目: constellation   文件: CameraIOProviderV0.java
/**
 * 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();
}
 
源代码3 项目: oneops   文件: MetricsElasticsearchModule.java
@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();
}
 
源代码4 项目: carbon-apimgt   文件: TracingReporter.java
/**
 * 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;
    }
}
 
@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();
}
 
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();
  }
}
 
源代码7 项目: katharsis-framework   文件: ErrorDataSerializer.java
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();
    }
}
 
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();
  }
}
 
源代码9 项目: glowroot   文件: TraceCommonService.java
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);
    }
}
 
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();
  }
}
 
源代码11 项目: constellation   文件: TransactionTypeIOProvider.java
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());
}
 
源代码12 项目: steady   文件: ASTSignatureChangeSerializer.java
/**
 * 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();
}
 
源代码13 项目: rdf4j   文件: RDFJSONWriter.java
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();
}
 
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();
  }
}
 
源代码15 项目: pysonar2   文件: JSONDump.java
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();
    }
}
 
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());
  }
}
 
源代码17 项目: iceberg   文件: SnapshotParser.java
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();
}
 
源代码18 项目: vespa   文件: JsonSerializationHelper.java
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();
}
 
源代码19 项目: constellation   文件: VertexTypeIOProvider.java
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());
}
 
@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();
}