Java Code Examples for com.dslplatform.json.JsonWriter#writeString()
The following examples show how to use
com.dslplatform.json.JsonWriter#writeString() .
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: DslJsonSerializer.java From apm-agent-java with Apache License 2.0 | 6 votes |
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 2
Source File: BValueJsonCodec.java From gridgo with MIT License | 6 votes |
@Override public void write(JsonWriter writer, BValue value) { if (value == null || value.isNull()) { writer.writeNull(); return; } switch (value.getType()) { case CHAR: writer.writeString(value.getString()); break; case RAW: writer.writeString(ByteArrayUtils.toHex(value.getRaw(), "0x")); break; default: writer.serializeObject(value.getData()); break; } }
Example 3
Source File: DslJsonSerializer.java From apm-agent-java with Apache License 2.0 | 5 votes |
private static void writeStringBuilderValue(StringBuilder value, JsonWriter jw) { if (value.length() > MAX_VALUE_LENGTH) { value.setLength(MAX_VALUE_LENGTH - 1); value.append('…'); } jw.writeString(value); }
Example 4
Source File: DslJsonSerializer.java From apm-agent-java with Apache License 2.0 | 5 votes |
private static void writeStringValue(CharSequence value, StringBuilder replaceBuilder, JsonWriter jw) { if (value.length() > MAX_VALUE_LENGTH) { replaceBuilder.setLength(0); replaceBuilder.append(value, 0, Math.min(value.length(), MAX_VALUE_LENGTH + 1)); writeStringBuilderValue(replaceBuilder, jw); } else { jw.writeString(value); } }
Example 5
Source File: DslJsonSerializer.java From apm-agent-java with Apache License 2.0 | 5 votes |
private static void writeLongStringBuilderValue(StringBuilder value, JsonWriter jw) { if (value.length() > MAX_LONG_STRING_VALUE_LENGTH) { value.setLength(MAX_LONG_STRING_VALUE_LENGTH - 1); value.append('…'); } jw.writeString(value); }
Example 6
Source File: DslJsonSerializer.java From apm-agent-java with Apache License 2.0 | 5 votes |
private static void writeLongStringValue(CharSequence value, StringBuilder replaceBuilder, JsonWriter jw) { if (value.length() > MAX_LONG_STRING_VALUE_LENGTH) { replaceBuilder.setLength(0); replaceBuilder.append(value, 0, Math.min(value.length(), MAX_LONG_STRING_VALUE_LENGTH + 1)); writeLongStringBuilderValue(replaceBuilder, jw); } else { jw.writeString(value); } }
Example 7
Source File: BObjectJsonCodec.java From gridgo with MIT License | 5 votes |
@Override public void write(JsonWriter writer, BObject value) { if (value == null) { writer.writeNull(); return; } writer.writeByte(JsonWriter.OBJECT_START); final int size = value.size(); if (size > 0) { final Iterator<Map.Entry<String, BElement>> iterator = value.entrySet().iterator(); Map.Entry<String, BElement> kv = iterator.next(); writer.writeString(kv.getKey()); writer.writeByte(JsonWriter.SEMI); compositeCodec.write(writer, kv.getValue()); for (int i = 1; i < size; i++) { kv = iterator.next(); var val = kv.getValue(); if ((val == null || val.isNullValue()) && this.compactMode == COMPACT) continue; writer.writeByte(JsonWriter.COMMA); writer.writeString(kv.getKey()); writer.writeByte(JsonWriter.SEMI); compositeCodec.write(writer, val); } } writer.writeByte(JsonWriter.OBJECT_END); }
Example 8
Source File: BReferenceCompactJsonCodec.java From gridgo with MIT License | 5 votes |
private void tryWriteWaitingKey(JsonWriter writer, AtomicReference<String> keyRef) { if (keyRef.get() == null) return; writer.writeString(keyRef.get()); writer.writeByte(SEMI); keyRef.set(null); }
Example 9
Source File: EnumDescription.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void write(final JsonWriter writer, @Nullable final T value) { if (value == null) writer.writeNull(); else writer.writeString(value.name()); }