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

The following examples show how to use com.fasterxml.jackson.core.JsonGenerator#writeNumberField() . 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: TraceCommonService.java    From glowroot with Apache License 2.0 6 votes vote down vote up
private static void writeTimer(Trace.Timer timer, JsonGenerator jg) throws IOException {
    jg.writeStartObject();
    jg.writeStringField("name", timer.getName());
    boolean extended = timer.getExtended();
    if (extended) {
        jg.writeBooleanField("extended", extended);
    }
    jg.writeNumberField("totalNanos", timer.getTotalNanos());
    jg.writeNumberField("count", timer.getCount());
    boolean active = timer.getActive();
    if (active) {
        jg.writeBooleanField("active", active);
    }
    List<Trace.Timer> childTimers = timer.getChildTimerList();
    if (!childTimers.isEmpty()) {
        jg.writeArrayFieldStart("childTimers");
        for (Trace.Timer childTimer : childTimers) {
            writeTimer(childTimer, jg);
        }
        jg.writeEndArray();
    }
    jg.writeEndObject();
}
 
Example 2
Source File: PKBeanBindMap.java    From kripton with Apache License 2.0 6 votes vote down vote up
@Override
public int serializeOnJackson(PKBean object, JsonGenerator jacksonSerializer) throws Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

  // field description (mapped with "description")
  if (object.description!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("description", object.description);
  }

  // field id (mapped with "id")
  fieldCount++;
  jacksonSerializer.writeNumberField("id", object.id);

  jacksonSerializer.writeEndObject();
  return fieldCount;
}
 
Example 3
Source File: MetricsElasticsearchModule.java    From oneops with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(JsonMeter jsonMeter,
                      JsonGenerator json,
                      SerializerProvider provider) throws IOException {
    json.writeStartObject();
    json.writeStringField("name", jsonMeter.name());
    json.writeObjectField(timestampFieldname, jsonMeter.timestampAsDate());
    Meter meter = jsonMeter.value();
    json.writeNumberField("count", meter.getCount());
    json.writeNumberField("m1_rate", meter.getOneMinuteRate() * rateFactor);
    json.writeNumberField("m5_rate", meter.getFiveMinuteRate() * rateFactor);
    json.writeNumberField("m15_rate", meter.getFifteenMinuteRate() * rateFactor);
    json.writeNumberField("mean_rate", meter.getMeanRate() * rateFactor);
    json.writeStringField("units", rateUnit);
    addOneOpsMetadata(json);
    json.writeEndObject();
}
 
Example 4
Source File: GridJettyObjectMapper.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param e Exception to write.
 * @param gen JSON generator.
 * @throws IOException If failed to write.
 */
private void writeException(Throwable e, JsonGenerator gen) throws IOException {
    if (e instanceof VisorExceptionWrapper) {
        VisorExceptionWrapper wrapper = (VisorExceptionWrapper)e;

        gen.writeStringField("className", wrapper.getClassName());
    }
    else
        gen.writeStringField("className", e.getClass().getName());

    if (e.getMessage() != null)
        gen.writeStringField("message", e.getMessage());

    if (e instanceof SQLException) {
        SQLException sqlE = (SQLException)e;

        gen.writeNumberField("errorCode", sqlE.getErrorCode());
        gen.writeStringField("SQLState", sqlE.getSQLState());
    }
}
 
Example 5
Source File: ArtistBindMap.java    From kripton with Apache License 2.0 6 votes vote down vote up
@Override
public int serializeOnJackson(Artist object, JsonGenerator jacksonSerializer) throws Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

  // field id (mapped with "id")
  fieldCount++;
  jacksonSerializer.writeNumberField("id", object.getId());

  // field name (mapped with "name")
  if (object.getName()!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("name", object.getName());
  }

  jacksonSerializer.writeEndObject();
  return fieldCount;
}
 
Example 6
Source File: PersonBindMap.java    From kripton with Apache License 2.0 6 votes vote down vote up
@Override
public int serializeOnJackson(Person object, JsonGenerator jacksonSerializer) throws Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

  // field id (mapped with "id")
  fieldCount++;
  jacksonSerializer.writeNumberField("id", object.id);

  // field image (mapped with "image")
  if (object.image!=null)  {
    fieldCount++;
    jacksonSerializer.writeBinaryField("image", object.image);
  }

  // field name (mapped with "name")
  if (object.name!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("name", object.name);
  }

  jacksonSerializer.writeEndObject();
  return fieldCount;
}
 
Example 7
Source File: AdminJsonService.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@POST(path = "/backend/admin/analyze-h2-disk-space", permission = "")
String analyzeH2DiskSpace(@BindAuthentication Authentication authentication) throws Exception {
    if (!offlineViewer && !authentication.isAdminPermitted("admin:edit:storage")) {
        throw new JsonServiceException(HttpResponseStatus.FORBIDDEN);
    }
    long h2DataFileSize = repoAdmin.getH2DataFileSize();
    List<H2Table> tables = repoAdmin.analyzeH2DiskSpace();
    StringBuilder sb = new StringBuilder();
    JsonGenerator jg = mapper.getFactory().createGenerator(CharStreams.asWriter(sb));
    try {
        jg.writeStartObject();
        jg.writeNumberField("h2DataFileSize", h2DataFileSize);
        jg.writeObjectField("tables", orderingByBytesDesc.sortedCopy(tables));
        jg.writeEndObject();
    } finally {
        jg.close();
    }
    return sb.toString();
}
 
Example 8
Source File: NakadiMetricsModule.java    From nakadi with MIT License 6 votes vote down vote up
@Override
public void serialize(final Timer timer,
                      final JsonGenerator json,
                      final SerializerProvider provider) throws IOException {
    json.writeStartObject();
    final Snapshot snapshot = timer.getSnapshot();
    json.writeNumberField("count", timer.getCount());
    json.writeNumberField("mean", snapshot.getMean() * durationFactor);

    if (showSamples) {
        final long[] values = snapshot.getValues();
        final double[] scaledValues = new double[values.length];
        for (int i = 0; i < values.length; i++) {
            scaledValues[i] = values[i] * durationFactor;
        }
        json.writeObjectField("values", scaledValues);
    }

    json.writeNumberField("m1_rate", timer.getOneMinuteRate() * rateFactor);
    json.writeStringField("duration_units", durationUnit);
    json.writeStringField("rate_units", rateUnit);
    json.writeEndObject();
}
 
Example 9
Source File: NakadiMetricsModule.java    From nakadi with MIT License 5 votes vote down vote up
@Override
public void serialize(final Histogram histogram,
                      final JsonGenerator json,
                      final SerializerProvider provider) throws IOException {
    json.writeStartObject();
    final Snapshot snapshot = histogram.getSnapshot();
    json.writeNumberField("count", histogram.getCount());
    json.writeNumberField("mean", snapshot.getMean());

    if (showSamples) {
        json.writeObjectField("values", snapshot.getValues());
    }

    json.writeEndObject();
}
 
Example 10
Source File: ApplicationAgentHostListSerializer.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(ApplicationAgentHostList applicationAgentHostList, JsonGenerator jsonGenerator, SerializerProvider provider) throws IOException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeNumberField("startIndex", applicationAgentHostList.getStartApplicationIndex());
    jsonGenerator.writeNumberField("endIndex", applicationAgentHostList.getEndApplicationIndex());
    jsonGenerator.writeNumberField("totalApplications", applicationAgentHostList.getTotalApplications());

    jsonGenerator.writeArrayFieldStart("applications");
    writeApplicationList(applicationAgentHostList, jsonGenerator);
    jsonGenerator.writeEndArray();

    jsonGenerator.writeEndObject();
}
 
Example 11
Source File: OpenRtbNativeJsonWriter.java    From openrtb with Apache License 2.0 5 votes vote down vote up
protected void writeRespTitleFields(NativeResponse.Asset.Title title, JsonGenerator gen)
    throws IOException {
  gen.writeStringField("text", title.getText());
  if (title.hasLen()) {
    gen.writeNumberField("len", title.getLen());
  }
}
 
Example 12
Source File: IdWrapperSerializer.java    From spring-boot-rest-api-helpers with MIT License 5 votes vote down vote up
@Override
public void serialize(Integer swe,
                      JsonGenerator jgen,
                      SerializerProvider sp) throws IOException, JsonGenerationException {

    jgen.writeStartObject();
    jgen.writeNumberField("id", swe);
    jgen.writeEndObject();
}
 
Example 13
Source File: AlertingService.java    From glowroot with Apache License 2.0 5 votes vote down vote up
private void sendSlackWithRetry(String centralDisplay, String agentRollupDisplay,
        String slackWebhookUrl, String slackChannel, long endTime, String subject,
        String messageText, boolean ok) {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        JsonGenerator jg = ObjectMappers.create().getFactory().createGenerator(baos);
        try {
            jg.writeStartObject();
            jg.writeArrayFieldStart("attachments");
            jg.writeStartObject();
            if (!agentRollupDisplay.isEmpty()) {
                subject = "[" + agentRollupDisplay + "] " + subject;
            }
            if (!centralDisplay.isEmpty()) {
                subject = "[" + centralDisplay + "] " + subject;
            }
            jg.writeStringField("fallback", subject + " - " + messageText);
            jg.writeStringField("pretext", subject);
            jg.writeStringField("color", ok ? "good" : "danger");
            jg.writeStringField("text", messageText);
            jg.writeNumberField("ts", endTime / 1000.0);
            jg.writeEndObject();
            jg.writeEndArray();
            jg.writeStringField("channel", slackChannel);
            jg.writeEndObject();
        } finally {
            jg.close();
        }
        httpClient.post(slackWebhookUrl, baos.toByteArray(), "application/json");
    } catch (Throwable t) {
        logger.error("{} - {}", agentRollupDisplay, t.getMessage(), t);
    }
}
 
Example 14
Source File: BeanInnerBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
@Override
public int serializeOnJackson(BeanInner object, JsonGenerator jacksonSerializer) throws
    Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

  // field id (mapped with "id")
  fieldCount++;
  jacksonSerializer.writeNumberField("id", object.id);

  jacksonSerializer.writeEndObject();
  return fieldCount;
}
 
Example 15
Source File: CollegeStudentBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
@Override
public int serializeOnJackson(CollegeStudent object, JsonGenerator jacksonSerializer) throws
    Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

  // field firstName (mapped with "firstName")
  if (object.firstName!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("firstName", object.firstName);
  }

  // field id (mapped with "id")
  fieldCount++;
  jacksonSerializer.writeNumberField("id", object.id);

  // field surname (mapped with "surname")
  if (object.surname!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("surname", object.surname);
  }

  jacksonSerializer.writeEndObject();
  return fieldCount;
}
 
Example 16
Source File: AgentEventMarkerSerializer.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(AgentEventMarker agentEventMarker, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException {
    jsonGenerator.writeStartObject();
    jsonGenerator.writeNumberField("totalCount", agentEventMarker.getTotalCount());
    jsonGenerator.writeFieldName("typeCounts");
    jsonGenerator.writeStartArray(agentEventMarker.getTypeCounts().size());
    for (Map.Entry<AgentEventType, Integer> e : agentEventMarker.getTypeCounts().entrySet()) {
        writeAgentEventTypeCount(jsonGenerator, e);
    }
    jsonGenerator.writeEndArray();
    jsonGenerator.writeEndObject();
}
 
Example 17
Source File: LongObjectIOProvider.java    From constellation with Apache License 2.0 5 votes vote down vote up
@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 Long attributeValue = graph.getObjectValue(attribute.getId(), elementId);
        if (attributeValue != null) {
            jsonGenerator.writeNumberField(attribute.getName(), attributeValue);
        } else {
            jsonGenerator.writeNullField(attribute.getName());
        }
    }
}
 
Example 18
Source File: PhoneNumberBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public int serializeOnJackson(PhoneNumber object, JsonGenerator jacksonSerializer) throws
    Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

  // field actionType (mapped with "actionType")
  if (object.actionType!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("actionType", object.actionType.toString());
  }

  // field contactId (mapped with "contactId")
  if (object.contactId!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("contactId", object.contactId);
  }

  // field contactName (mapped with "contactName")
  if (object.contactName!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("contactName", object.contactName);
  }

  // field countryCode (mapped with "countryCode")
  if (object.countryCode!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("countryCode", object.countryCode);
  }

  // field id (mapped with "id")
  fieldCount++;
  jacksonSerializer.writeNumberField("id", object.id);

  // field number (mapped with "number")
  if (object.number!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("number", object.number);
  }

  jacksonSerializer.writeEndObject();
  return fieldCount;
}
 
Example 19
Source File: MockAnimationBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public int serializeOnJackson(MockAnimation object, JsonGenerator jacksonSerializer) throws
    Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

  // field name (mapped with "name")
  if (object.getName()!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("name", object.getName());
  }

  // field loop (mapped with "loop")
  fieldCount++;
  jacksonSerializer.writeBooleanField("loop", object.isLoop());

  // field rate (mapped with "rate")
  fieldCount++;
  jacksonSerializer.writeNumberField("rate", object.getRate());

  // field frames (mapped with "frames")
  if (object.frames!=null)  {
    fieldCount++;
    int n=object.frames.size();
    MockKeyFrame item;
    // write wrapper tag
    jacksonSerializer.writeFieldName("frames");
    jacksonSerializer.writeStartArray();
    for (int i=0; i<n; i++) {
      item=object.frames.get(i);
      if (item==null) {
        jacksonSerializer.writeNull();
      } else {
        mockKeyFrameBindMap.serializeOnJackson(item, jacksonSerializer);
      }
    }
    jacksonSerializer.writeEndArray();
  }

  jacksonSerializer.writeEndObject();
  return fieldCount;
}
 
Example 20
Source File: CountryBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
@Override
public int serializeOnJackson(Country object, JsonGenerator jacksonSerializer) throws Exception {
  jacksonSerializer.writeStartObject();
  int fieldCount=0;

  // Serialized Field:

  // field area (mapped with "area")
  fieldCount++;
  jacksonSerializer.writeNumberField("area", object.area);

  // field callingCode (mapped with "callingCode")
  if (object.callingCode!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("callingCode", object.callingCode);
  }

  // field code (mapped with "code")
  if (object.code!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("code", object.code);
  }

  // field id (mapped with "id")
  fieldCount++;
  jacksonSerializer.writeNumberField("id", object.id);

  // field name (mapped with "name")
  if (object.name!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("name", object.name);
  }

  // field region (mapped with "region")
  if (object.region!=null)  {
    fieldCount++;
    jacksonSerializer.writeStringField("region", object.region);
  }

  // field translatedName (mapped with "translatedName")
  if (object.translatedName!=null)  {
    fieldCount++;
    // write wrapper tag
    if (object.translatedName.size()>0) {
      jacksonSerializer.writeFieldName("translatedName");
      jacksonSerializer.writeStartArray();
      for (Map.Entry<Translation, String> item: object.translatedName.entrySet()) {
        jacksonSerializer.writeStartObject();
        jacksonSerializer.writeStringField("key", item.getKey().toString());
        if (item.getValue()==null) {
          jacksonSerializer.writeNullField("value");
        } else {
          jacksonSerializer.writeStringField("value", item.getValue());
        }
        jacksonSerializer.writeEndObject();
      }
      jacksonSerializer.writeEndArray();
    } else {
      jacksonSerializer.writeNullField("translatedName");
    }
  }

  jacksonSerializer.writeEndObject();
  return fieldCount;
}