Java Code Examples for com.fasterxml.jackson.core.JsonGenerator#writeObjectField()

The following examples show how to use com.fasterxml.jackson.core.JsonGenerator#writeObjectField() . 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: AbstractChartSerializer.java    From beakerx with Apache License 2.0 6 votes vote down vote up
protected void serialize(T chart, JsonGenerator jgen) throws IOException {

    super.serialize(chart, jgen);

    jgen.writeObjectField(DOMAIN_AXIS_LABEL, chart.getXLabel());
    jgen.writeObjectField(Y_LABEL, chart.getYLabel());
    jgen.writeObjectField(RANGE_AXES, chart.getYAxes());
    jgen.writeObjectField(X_LOWER_MARGIN, chart.getXLowerMargin());
    jgen.writeObjectField(X_UPPER_MARGIN, chart.getXUpperMargin());
    jgen.writeObjectField(Y_AUTO_RANGE, chart.getYAutoRange());
    jgen.writeObjectField(Y_AUTO_RANGE_INCLUDES_ZERO, chart.getYAutoRangeIncludesZero());
    jgen.writeObjectField(Y_LOWER_MARGIN, chart.getYLowerMargin());
    jgen.writeObjectField(Y_UPPER_MARGIN, chart.getYUpperMargin());
    jgen.writeObjectField(Y_LOWER_BOUND, chart.getYLowerBound());
    jgen.writeObjectField(Y_UPPER_BOUND, chart.getYUpperBound());
    jgen.writeObjectField(LOG_Y, chart.getLogY());
    jgen.writeObjectField(TIMEZONE, chart.getTimeZone());
    jgen.writeObjectField(CROSSHAIR, chart.getCrosshair());
    jgen.writeObjectField(OMIT_CHECKBOXES, chart.getOmitCheckboxes());
    jgen.writeObjectField(AUTO_ZOOM, chart.getAutoZoom());
  }
 
Example 2
Source File: ChartSerializer.java    From beakerx with Apache License 2.0 6 votes vote down vote up
protected void serialize(T chart, JsonGenerator jgen) throws IOException {

    super.serialize(chart, jgen);

    String type = SerializerUtil.getTypeName(chart);
    if ("SimpleTimePlot".equals(type)){
      jgen.writeObjectField("type", "TimePlot");
    }else {
      jgen.writeObjectField("type", type);
    }

    jgen.writeObjectField(INIT_WIDTH, chart.getInitWidth());
    jgen.writeObjectField(INIT_HEIGHT, chart.getInitHeight());
    jgen.writeObjectField(CHART_TITLE, chart.getTitle());
    jgen.writeObjectField(SHOW_LEGEND, chart.getShowLegend());
    jgen.writeObjectField(USE_TOOL_TIP, chart.getUseToolTip());
    jgen.writeObjectField(LEGEND_POSITION, chart.getLegendPosition());
    jgen.writeObjectField(LEGEND_LAYOUT, chart.getLegendLayout());
    jgen.writeObjectField(CUSTOM_STYLES, chart.getCustomStyles());
    jgen.writeObjectField(ELEMENT_STYLES, chart.getElementStyles());
  }
 
Example 3
Source File: MetricsElasticsearchModule.java    From oneops with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(JsonHistogram jsonHistogram,
                      JsonGenerator json,
                      SerializerProvider provider) throws IOException {
    json.writeStartObject();
    json.writeStringField("name", jsonHistogram.name());
    json.writeObjectField(timestampFieldname, jsonHistogram.timestampAsDate());
    Histogram histogram = jsonHistogram.value();

    final Snapshot snapshot = histogram.getSnapshot();
    json.writeNumberField("count", histogram.getCount());
    json.writeNumberField("max", snapshot.getMax());
    json.writeNumberField("mean", snapshot.getMean());
    json.writeNumberField("min", snapshot.getMin());
    json.writeNumberField("p50", snapshot.getMedian());
    json.writeNumberField("p75", snapshot.get75thPercentile());
    json.writeNumberField("p95", snapshot.get95thPercentile());
    json.writeNumberField("p98", snapshot.get98thPercentile());
    json.writeNumberField("p99", snapshot.get99thPercentile());
    json.writeNumberField("p999", snapshot.get999thPercentile());

    json.writeNumberField("stddev", snapshot.getStdDev());
    addOneOpsMetadata(json);
    json.writeEndObject();
}
 
Example 4
Source File: JSonBindingUtils.java    From roboconf-platform with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(
		TargetAssociation item,
		JsonGenerator generator,
		SerializerProvider provider )
throws IOException {

	generator.writeStartObject();
	if( item.getInstancePathOrComponentName() != null )
		generator.writeStringField( PATH, item.getInstancePathOrComponentName());

	if( item.getInstanceComponent() != null )
		generator.writeStringField( INST_COMPONENT, item.getInstanceComponent());

	if( item.getTargetDescriptor() != null )
		generator.writeObjectField( DESC, item.getTargetDescriptor());

	generator.writeEndObject();
}
 
Example 5
Source File: RntbdTransportClient.java    From azure-cosmosdb-java with MIT License 6 votes vote down vote up
@Override
public void serialize(

    final RntbdTransportClient value,
    final JsonGenerator generator,
    final SerializerProvider provider

) throws IOException {

    generator.writeStartObject();
    generator.writeNumberField("id", value.id());
    generator.writeBooleanField("isClosed", value.isClosed());
    generator.writeObjectField("configuration", value.endpointProvider.config());
    generator.writeObjectFieldStart("serviceEndpoints");
    generator.writeNumberField("count", value.endpointCount());
    generator.writeArrayFieldStart("items");

    for (final Iterator<RntbdEndpoint> iterator = value.endpointProvider.list().iterator(); iterator.hasNext(); ) {
        generator.writeObject(iterator.next());
    }

    generator.writeEndArray();
    generator.writeEndObject();
    generator.writeEndObject();
}
 
Example 6
Source File: NodeHistogramSummarySerializer.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
private void writeHistogram(JsonGenerator jgen, NodeHistogram nodeHistogram) throws IOException {
    Histogram applicationHistogram = nodeHistogram.getApplicationHistogram();
    if (applicationHistogram == null) {
        writeEmptyObject(jgen, "histogram");
    } else {
        jgen.writeObjectField("histogram", applicationHistogram);
    }
    Map<String, Histogram> agentHistogramMap = nodeHistogram.getAgentHistogramMap();
    if(agentHistogramMap == null) {
        writeEmptyObject(jgen, "agentHistogram");
    } else {
        jgen.writeObjectField("agentHistogram", agentHistogramMap);
    }

    List<ResponseTimeViewModel> applicationTimeSeriesHistogram = nodeHistogram.getApplicationTimeHistogram();
    if (applicationTimeSeriesHistogram == null) {
        writeEmptyArray(jgen, "timeSeriesHistogram");
    } else {
        jgen.writeObjectField("timeSeriesHistogram", applicationTimeSeriesHistogram);
    }

    AgentResponseTimeViewModelList agentTimeSeriesHistogram = nodeHistogram.getAgentTimeHistogram();
    jgen.writeObject(agentTimeSeriesHistogram);
}
 
Example 7
Source File: ConstantLineSerializer.java    From beakerx with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(ConstantLine constantLine, JsonGenerator jgen, SerializerProvider sp)
  throws IOException, JsonProcessingException {

  jgen.writeStartObject();

  boolean isNanoPlot = NanoPlot.isNanoPlotClass(constantLine.getPlotType());
  jgen.writeObjectField(TYPE, SerializerUtil.getTypeName(constantLine));
  jgen.writeObjectField("x", isNanoPlot ? processLargeNumber(constantLine.getX()) : constantLine.getX());
  jgen.writeObjectField("y", constantLine.getY());
  jgen.writeObjectField("visible", constantLine.getVisible());
  jgen.writeObjectField("yAxis", constantLine.getYAxis());
  jgen.writeObjectField("showLabel", constantLine.getShowLabel());
  if (constantLine.getWidth() != null) {
    jgen.writeObjectField("width", constantLine.getWidth());
  }
  if (constantLine.getStyle() != null) {
    jgen.writeObjectField("style", constantLine.getStyle().toString());
  }
  if (constantLine.getColor() instanceof Color) {
    jgen.writeObjectField("color", constantLine.getColor());
  }

  jgen.writeEndObject();
}
 
Example 8
Source File: AwsIotJsonSerializer.java    From aws-iot-device-sdk-java with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(AbstractAwsIotDevice device, JsonGenerator generator, SerializerProvider provider)
        throws IOException, JsonProcessingException {
    generator.writeStartObject();

    try {
        for (String property : device.getReportedProperties().keySet()) {
            Field field = device.getReportedProperties().get(property);

            Object value = invokeGetterMethod(device, field);
            generator.writeObjectField(property, value);
        }
    } catch (IllegalArgumentException e) {
        throw new IOException(e);
    }

    generator.writeEndObject();
}
 
Example 9
Source File: ODataErrorSerializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@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 10
Source File: UnwrappingFunctionSerializer.java    From yare with MIT License 5 votes vote down vote up
@Override
public void serialize(Function value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
    gen.writeFieldName(JsonPropertyNames.Function.FUNCTION);
    gen.writeStartObject();
    gen.writeObjectField(JsonPropertyNames.Function.NAME, value.getName());
    gen.writeObjectField(JsonPropertyNames.Function.RETURN_TYPE, value.getReturnType());
    gen.writeObjectField(JsonPropertyNames.Function.PARAMETERS, value.getParameters());
    gen.writeEndObject();
}
 
Example 11
Source File: MeasurementDTOSerializer.java    From newts with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(MeasurementDTO value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
    jgen.writeStartObject();
    jgen.writeStringField("name", value.getName());
    jgen.writeNumberField("timestamp", value.getTimestamp());
    jgen.writeNumberField("value", value.getValue());

    // Since attributes is optional, be compact and omit from JSON output when unused.
    if (value.getAttributes() != null && !value.getAttributes().isEmpty()) {
        jgen.writeObjectField("attributes", value.getAttributes());
    }

    jgen.writeEndObject();
}
 
Example 12
Source File: CategoryGraphicsSerializer.java    From beakerx with Apache License 2.0 5 votes vote down vote up
public void serialize(T graphics, JsonGenerator jgen, SerializerProvider sp) throws IOException {

    super.serialize(graphics, jgen, sp);

    jgen.writeObjectField("showItemLabel", graphics.getShowItemLabel());
    jgen.writeObjectField("center_series", graphics.getCenterSeries());
    jgen.writeObjectField("use_tool_tip", graphics.getUseToolTip());


    if (graphics.getSeriesNames() != null) {
      jgen.writeObjectField("seriesNames", graphics.getSeriesNames());
    }
    if (graphics.getValue() != null) {
      jgen.writeObjectField("value", graphics.getValue());

    }
    if (graphics.getColors() != null) {
      jgen.writeObjectField("colors", graphics.getColors());
    } else {
      jgen.writeObjectField("color", graphics.getColor());
    }

    String[][] itemLabels = graphics.getItemLabels();
    if (itemLabels != null){
      jgen.writeObjectField("itemLabels", itemLabels);
    }
  }
 
Example 13
Source File: DefaultAuthorizationDeniedResponse.java    From api-boot with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeResponse(ApiBootOAuth2Exception e, JsonGenerator generator) {
    try {
        String message = e.getMessage();
        if (message != null) {
            message = HtmlUtils.htmlEscape(message);
        }
        generator.writeObjectField("errorMessage", message);
        generator.writeObjectField("errorCode", HttpStatus.UNAUTHORIZED.getReasonPhrase());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
Example 14
Source File: TransactionJsonService.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@GET(path = "/backend/transaction/percentiles", permission = "agent:transaction:overview")
String getPercentiles(@BindAgentRollupId String agentRollupId,
        @BindRequest TransactionPercentileRequest request, @BindAutoRefresh boolean autoRefresh)
        throws Exception {
    AggregateQuery query = toChartQuery(request, DataKind.GENERAL);
    long liveCaptureTime = clock.currentTimeMillis();
    List<PercentileAggregate> percentileAggregates =
            transactionCommonService.getPercentileAggregates(agentRollupId, query, autoRefresh);
    if (percentileAggregates.isEmpty() && fallBackToLargestAggregates(query)) {
        // fall back to largest aggregates in case expiration settings have recently changed
        query = withLargestRollupLevel(query);
        percentileAggregates = transactionCommonService.getPercentileAggregates(agentRollupId,
                query, autoRefresh);
        if (!percentileAggregates.isEmpty() && ignoreFallBackData(query,
                Iterables.getLast(percentileAggregates).captureTime())) {
            // this is probably data from before the requested time period
            percentileAggregates = ImmutableList.of();
        }
    }
    long dataPointIntervalMillis =
            configRepository.getRollupConfigs().get(query.rollupLevel()).intervalMillis();
    PercentileData percentileData =
            getDataSeriesForPercentileChart(request, percentileAggregates, request.percentile(),
                    dataPointIntervalMillis, liveCaptureTime);
    Map<Long, Long> transactionCounts = getTransactionCounts2(percentileAggregates);

    StringBuilder sb = new StringBuilder();
    JsonGenerator jg = mapper.getFactory().createGenerator(CharStreams.asWriter(sb));
    try {
        jg.writeStartObject();
        jg.writeObjectField("dataSeries", percentileData.dataSeriesList());
        jg.writeNumberField("dataPointIntervalMillis", dataPointIntervalMillis);
        jg.writeObjectField("transactionCounts", transactionCounts);
        jg.writeObjectField("mergedAggregate", percentileData.mergedAggregate());
        jg.writeEndObject();
    } finally {
        jg.close();
    }
    return sb.toString();
}
 
Example 15
Source File: ExternalTestRunnerTestSpec.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
    throws IOException {
  jsonGenerator.writeStartObject();
  jsonGenerator.writeStringField("target", getTarget().toString());
  jsonGenerator.writeStringField("type", getType());
  jsonGenerator.writeObjectField("command", getCommand());
  jsonGenerator.writeObjectField("cwd", getCwd().toAbsolutePath().toString());
  jsonGenerator.writeObjectField("env", getEnv());
  if (!getNeededCoverage().isEmpty()) {
    jsonGenerator.writeObjectField(
        "needed_coverage",
        Iterables.transform(
            getNeededCoverage(), input -> ImmutableList.of(input.getFirst(), input.getSecond())));
  }
  if (!getAdditionalCoverageTargets().isEmpty()) {
    jsonGenerator.writeObjectField("additional_coverage_targets", getAdditionalCoverageTargets());
  }
  if (!getRequiredPaths().isEmpty()) {
    jsonGenerator.writeObjectField("required_paths", getRequiredPaths());
  }
  jsonGenerator.writeObjectField(
      "labels",
      getLabels().stream().map(Object::toString).collect(ImmutableList.toImmutableList()));
  jsonGenerator.writeObjectField("contacts", getContacts());
  jsonGenerator.writeEndObject();
}
 
Example 16
Source File: SingleWrapper.java    From kaif with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(SingleWrapper<?> value, JsonGenerator jgen, SerializerProvider provider)
    throws IOException, JsonProcessingException {
  jgen.writeStartObject();
  jgen.writeObjectField(value.getFieldName(), value.getValue());
  jgen.writeEndObject();
}
 
Example 17
Source File: GaugeValueJsonService.java    From glowroot with Apache License 2.0 4 votes vote down vote up
@GET(path = "/backend/jvm/gauges", permission = "agent:jvm:gauges")
String getGaugeValues(@BindAgentRollupId String agentRollupId,
        @BindRequest GaugeValueRequest request) throws Exception {
    int rollupLevel = rollupLevelService.getGaugeRollupLevelForView(request.from(),
            request.to(), agentRollupId.endsWith("::"));
    long dataPointIntervalMillis;
    if (rollupLevel == 0) {
        dataPointIntervalMillis = configRepository.getGaugeCollectionIntervalMillis();
    } else {
        dataPointIntervalMillis =
                configRepository.getRollupConfigs().get(rollupLevel - 1).intervalMillis();
    }
    Map<String, List<GaugeValue>> origGaugeValues =
            getGaugeValues(agentRollupId, request, rollupLevel, dataPointIntervalMillis);
    Map<String, List<GaugeValue>> gaugeValues = origGaugeValues;
    if (isEmpty(gaugeValues)
            && noHarmFallingBackToLargestAggregate(agentRollupId, rollupLevel, request)) {
        // fall back to largest aggregates in case expiration settings have recently changed
        rollupLevel = getLargestRollupLevel();
        dataPointIntervalMillis =
                configRepository.getRollupConfigs().get(rollupLevel - 1).intervalMillis();
        gaugeValues =
                getGaugeValues(agentRollupId, request, rollupLevel, dataPointIntervalMillis);
        long lastCaptureTime = 0;
        for (List<GaugeValue> list : gaugeValues.values()) {
            if (!list.isEmpty()) {
                lastCaptureTime =
                        Math.max(lastCaptureTime, Iterables.getLast(list).getCaptureTime());
            }
        }
        if (lastCaptureTime != 0 && ignoreFallBackData(request, lastCaptureTime)) {
            // this is probably data from before the requested time period
            // (go back to empty gauge values)
            gaugeValues = origGaugeValues;
        }
    }
    if (rollupLevel != 0) {
        syncManualRollupCaptureTimes(gaugeValues, rollupLevel);
    }
    double gapMillis = dataPointIntervalMillis * 1.5;
    List<DataSeries> dataSeriesList = Lists.newArrayList();
    for (Map.Entry<String, List<GaugeValue>> entry : gaugeValues.entrySet()) {
        dataSeriesList
                .add(convertToDataSeriesWithGaps(entry.getKey(), entry.getValue(), gapMillis));
    }
    List<Gauge> gauges =
            gaugeValueRepository.getGauges(agentRollupId, request.from(), request.to());
    List<Gauge> sortedGauges = new GaugeOrdering().immutableSortedCopy(gauges);
    sortedGauges = addCounterSuffixesIfAndWhereNeeded(sortedGauges);
    StringBuilder sb = new StringBuilder();
    JsonGenerator jg = mapper.getFactory().createGenerator(CharStreams.asWriter(sb));
    try {
        jg.writeStartObject();
        jg.writeObjectField("dataSeries", dataSeriesList);
        jg.writeNumberField("dataPointIntervalMillis", dataPointIntervalMillis);
        jg.writeObjectField("allGauges", sortedGauges);
        jg.writeEndObject();
    } finally {
        jg.close();
    }
    return sb.toString();
}
 
Example 18
Source File: PlainJsonDocumentSerializer.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
private void writeMeta(JsonGenerator gen, ObjectNode meta, SerializerProvider serializerProvider) throws IOException {
	if (meta != null && !meta.isEmpty(serializerProvider)) {
		gen.writeObjectField("meta", meta);
	}
}
 
Example 19
Source File: AgentInfoSerializer.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(AgentInfo agentInfo, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
    jgen.writeStartObject();

    jgen.writeStringField("applicationName", agentInfo.getApplicationName());
    jgen.writeStringField("agentId", agentInfo.getAgentId());
    jgen.writeNumberField("startTimestamp", agentInfo.getStartTimestamp());
    jgen.writeStringField("hostName", agentInfo.getHostName());
    jgen.writeStringField("ip", agentInfo.getIp());
    jgen.writeStringField("ports", agentInfo.getPorts());
    final ServiceType serviceType = serviceTypeRegistryService.findServiceType(agentInfo.getServiceTypeCode());
    jgen.writeStringField("serviceType", serviceType.getDesc());
    jgen.writeNumberField("pid", agentInfo.getPid());
    jgen.writeStringField("vmVersion", agentInfo.getVmVersion());
    jgen.writeStringField("agentVersion", agentInfo.getAgentVersion());
    jgen.writeObjectField("serverMetaData", agentInfo.getServerMetaData());
    jgen.writeObjectField("jvmInfo", agentInfo.getJvmInfo());

    AgentStatus status = agentInfo.getStatus();
    if (status != null) {
        jgen.writeObjectField("status", status);
    }

    jgen.writeNumberField("initialStartTimestamp", agentInfo.getInitialStartTimestamp());

    if (matcherGroupList != null) {
        jgen.writeFieldName("linkList");
        jgen.writeStartArray();

        for (MatcherGroup matcherGroup : matcherGroupList) {
            if (matcherGroup.ismatchingType(agentInfo)) {
                LinkInfo linkInfo = matcherGroup.makeLinkInfo(agentInfo);
                jgen.writeStartObject();
                jgen.writeStringField("linkName", linkInfo.getLinkName());
                jgen.writeStringField("linkURL", linkInfo.getLinkUrl());
                jgen.writeStringField("linkType", linkInfo.getLinktype());
                jgen.writeEndObject();
            }
        }

        jgen.writeEndArray();
    }

    jgen.writeEndObject();
}
 
Example 20
Source File: AuthenticateSerializer.java    From simulacron with Apache License 2.0 4 votes vote down vote up
@Override
public void serializeMessage(
    Authenticate authenticate, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
    throws IOException {
  jsonGenerator.writeObjectField("authenticator", authenticate.authenticator);
}