com.dslplatform.json.NumberConverter Java Examples

The following examples show how to use com.dslplatform.json.NumberConverter. 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: MetricRegistrySerializer.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
static void serializeMetricSet(MetricSet metricSet, long epochMicros, StringBuilder replaceBuilder, JsonWriter jw) {
    jw.writeByte(JsonWriter.OBJECT_START);
    {
        DslJsonSerializer.writeFieldName("metricset", jw);
        jw.writeByte(JsonWriter.OBJECT_START);
        {
            DslJsonSerializer.writeFieldName("timestamp", jw);
            NumberConverter.serialize(epochMicros, jw);
            jw.writeByte(JsonWriter.COMMA);
            DslJsonSerializer.serializeLabels(metricSet.getLabels(), replaceBuilder, jw);
            DslJsonSerializer.writeFieldName("samples", jw);
            jw.writeByte(JsonWriter.OBJECT_START);
            boolean hasSamples = serializeGauges(metricSet.getGauges(), jw);
            hasSamples |= serializeTimers(metricSet.getTimers(), hasSamples, jw);
            serializeCounters(metricSet.getCounters(), hasSamples, jw);
            jw.writeByte(JsonWriter.OBJECT_END);
        }
        jw.writeByte(JsonWriter.OBJECT_END);
    }
    jw.writeByte(JsonWriter.OBJECT_END);
}
 
Example #2
Source File: DslJsonSerializer.java    From apm-agent-java with Apache License 2.0 6 votes vote down vote up
private static void serializeScalarValue(StringBuilder replaceBuilder, JsonWriter jw, Object value, boolean extendedStringLimit, boolean supportsNonStringValues) {
    if (value instanceof String) {
        if (extendedStringLimit) {
            writeLongStringValue((String) value, replaceBuilder, jw);
        } else {
            writeStringValue((String) value, replaceBuilder, jw);
        }
    } else if (value instanceof Number) {
        if (supportsNonStringValues) {
            NumberConverter.serialize(((Number) value).doubleValue(), jw);
        } else {
            jw.writeNull();
        }
    } else if (value instanceof Boolean) {
        if (supportsNonStringValues) {
            BoolConverter.serialize((Boolean) value, jw);
        } else {
            jw.writeNull();
        }
    } else {
        // can't happen, as AbstractContext enforces the values to be either String, Number or boolean
        jw.writeString("invalid value");
    }
}
 
Example #3
Source File: BValueJsonCodec.java    From gridgo with MIT License 6 votes vote down vote up
BValue read(JsonReader reader, boolean isBeginning) throws ParsingException, IOException {
    try {
        switch (reader.last()) {
        case 'n':
            if (!reader.wasNull())
                throw reader.newParseErrorAt("Expecting 'null' for null constant", 0);
            return BValue.of(null);
        case 't':
            if (!reader.wasTrue())
                throw reader.newParseErrorAt("Expecting 'true' for true constant", 0);
            return BValue.of(true);
        case 'f':
            if (!reader.wasFalse())
                throw reader.newParseErrorAt("Expecting 'false' for false constant", 0);
            return BValue.of(false);
        case '"':
            return BValue.of(reader.readString());
        default:
            return BValue.of(NumberConverter.deserializeNumber(reader));
        }
    } catch (ParsingException e) {
        if (isBeginning && !USE_STRICT)
            return BValue.of(reader.toString());
        throw e;
    }
}
 
Example #4
Source File: DslJsonSerializer.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
private void serializeResponse(final Response response) {
    if (response.hasContent()) {
        writeFieldName("response");
        jw.writeByte(OBJECT_START);
        writeField("headers", response.getHeaders());
        writeField("finished", response.isFinished());
        writeField("headers_sent", response.isHeadersSent());
        writeFieldName("status_code");
        NumberConverter.serialize(response.getStatusCode(), jw);
        jw.writeByte(OBJECT_END);
        jw.writeByte(COMMA);
    }
}
 
Example #5
Source File: MainActivity.java    From dsl-json with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void serialize(JsonWriter writer, boolean minimal) {
    writer.writeAscii("{\"x\":");
    NumberConverter.serialize(x, writer);
    writer.writeAscii(",\"s\":");
    StringConverter.serialize(s, writer);
    writer.writeAscii("}");
}
 
Example #6
Source File: MainActivity.java    From dsl-json with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void serialize(JsonWriter writer, boolean minimal) {
    writer.writeAscii("{\"x\":");
    NumberConverter.serialize(x, writer);
    writer.writeAscii(",\"s\":");
    StringConverter.serialize(s, writer);
    writer.writeAscii("}");
}
 
Example #7
Source File: World.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void serialize(JsonWriter writer, boolean minimal) {
    writer.writeAscii("{\"id\":");
    NumberConverter.serialize(this.id, writer);
    writer.writeAscii(",\"randomNumber\":");
    NumberConverter.serialize(this.randomNumber, writer);
    writer.writeByte(com.dslplatform.json.JsonWriter.OBJECT_END);
}
 
Example #8
Source File: MetricRegistrySerializer.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
private static void serializeCounter(String key, AtomicLong value, JsonWriter jw) {
    serializeValueStart(key, "", jw);
    NumberConverter.serialize(value.get(), jw);
    jw.writeByte(JsonWriter.OBJECT_END);
    value.set(0);
}
 
Example #9
Source File: MetricRegistrySerializer.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
private static void serializeValue(String key, String suffix, double value, JsonWriter jw) {
    serializeValueStart(key, suffix, jw);
    NumberConverter.serialize(value, jw);
    jw.writeByte(JsonWriter.OBJECT_END);
}
 
Example #10
Source File: MetricRegistrySerializer.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
private static void serializeValue(String key, String suffix, long value, JsonWriter jw) {
    serializeValueStart(key, suffix, jw);
    NumberConverter.serialize(value, jw);
    jw.writeByte(JsonWriter.OBJECT_END);
}
 
Example #11
Source File: DslJsonSerializer.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
private void writeField(final String fieldName, final long value) {
    writeFieldName(fieldName);
    NumberConverter.serialize(value, jw);
    jw.writeByte(COMMA);
}
 
Example #12
Source File: DslJsonSerializer.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
private void writeField(final String fieldName, final int value) {
    writeFieldName(fieldName);
    NumberConverter.serialize(value, jw);
    jw.writeByte(COMMA);
}
 
Example #13
Source File: DslJsonSerializer.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
private void writeLastField(final String fieldName, final int value) {
    writeFieldName(fieldName);
    NumberConverter.serialize(value, jw);
}
 
Example #14
Source File: DslJsonSerializer.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
private void writeField(final String fieldName, final double value) {
    writeFieldName(fieldName);
    NumberConverter.serialize(value, jw);
    jw.writeByte(COMMA);
}
 
Example #15
Source File: DslJsonSerializer.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
private void writeTimestamp(final long epochMicros) {
    writeFieldName("timestamp");
    NumberConverter.serialize(epochMicros, jw);
    jw.writeByte(COMMA);
}