Java Code Examples for com.dslplatform.json.JsonWriter#writeNull()
The following examples show how to use
com.dslplatform.json.JsonWriter#writeNull() .
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: BElementJsonCodec.java From gridgo with MIT License | 6 votes |
@Override public void write(JsonWriter writer, BElement value) { if (value == null) writer.writeNull(); if (value.isObject()) objectCodec.write(writer, value.asObject()); if (value.isArray()) arrayCodec.write(writer, value.asArray()); if (value.isValue()) valueCodec.write(writer, value.asValue()); if (value.isReference()) referenceCodec.write(writer, value.asReference()); }
Example 3
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 4
Source File: BArrayJsonCodec.java From gridgo with MIT License | 6 votes |
@Override public void write(JsonWriter writer, BArray value) { if (value == null) { writer.writeNull(); return; } writer.writeByte(JsonWriter.ARRAY_START); final int size = value.size(); if (size > 0) { final Iterator<BElement> iterator = value.iterator(); compositeCodec.write(writer, iterator.next()); for (int i = 1; i < size; i++) { writer.writeByte(JsonWriter.COMMA); compositeCodec.write(writer, iterator.next()); } } writer.writeByte(JsonWriter.ARRAY_END); }
Example 5
Source File: WriteDescription.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 6 votes |
public final void write(final JsonWriter writer, @Nullable final T instance) { if (instance == null) { writer.writeNull(); } else if (alwaysSerialize) { writer.writeByte(JsonWriter.OBJECT_START); writeContentFull(writer, instance); writer.writeByte(JsonWriter.OBJECT_END); } else { writer.writeByte(JsonWriter.OBJECT_START); if (writeContentMinimal(writer, instance)) { writer.getByteBuffer()[writer.size() - 1] = JsonWriter.OBJECT_END; } else { writer.writeByte(JsonWriter.OBJECT_END); } } }
Example 6
Source File: DslJsonSerializer.java From apm-agent-java with Apache License 2.0 | 5 votes |
static void writeLastField(final String fieldName, @Nullable final CharSequence value, StringBuilder replaceBuilder, final JsonWriter jw) { writeFieldName(fieldName, jw); if (value != null && value.length() > 0) { writeStringValue(value, replaceBuilder, jw); } else { jw.writeNull(); } }
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: ArrayFormatDescription.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public final void write(final JsonWriter writer, @Nullable final T instance) { if (instance == null) { writer.writeNull(); } else { writer.writeByte(JsonWriter.ARRAY_START); writeContentFull(writer, instance); writer.writeByte(JsonWriter.ARRAY_END); } }
Example 9
Source File: BReferenceJsonCodec.java From gridgo with MIT License | 4 votes |
@Override public void write(JsonWriter writer, BReference value) { Object reference; if (value == null || (reference = value.getReference()) == null) { writer.writeNull(); return; } var lengthStack = new Stack<Integer>(); var indexStack = new Stack<AtomicInteger>(); PojoGetter.of(reference, value.getterProxy()) // .shallowly(true) // .walker((indicator, val, signature, proxy) -> { switch (indicator) { case START_MAP: case START_ARRAY: tryIncreaseTopIndexerOnNewContainer(indexStack); writer.writeByte(indicator == START_ARRAY ? ARRAY_START : OBJECT_START); lengthStack.push((int) val); indexStack.push(new AtomicInteger(0)); break; case END_MAP: case END_ARRAY: indexStack.pop(); lengthStack.pop(); writer.writeByte(indicator == END_ARRAY ? ARRAY_END : OBJECT_END); tryWriteCommaAfterContainerEnd(writer, lengthStack, indexStack); break; case KEY_NULL: if (signature != null && signature.isIgnoreNull()) { indexStack.peek().incrementAndGet(); break; } case KEY: writer.writeString((String) val); writer.writeByte(SEMI); if (indicator == KEY_NULL) { writer.writeNull(); tryWriteCommaAfterValue(writer, lengthStack, indexStack); } break; case VALUE: var ele = BElement.wrapAny(val); if (val != ele && ele.isReference()) ele.asReference().getterProxy(proxy); writer.serializeObject(ele); tryWriteCommaAfterValue(writer, lengthStack, indexStack); break; } }).walk(); }
Example 10
Source File: BReferenceCompactJsonCodec.java From gridgo with MIT License | 4 votes |
@Override public void write(JsonWriter writer, BReference value) { Object reference; if (value == null || (reference = value.getReference()) == null) { writer.writeNull(); return; } var lengthStack = new Stack<Integer>(); var indexStack = new Stack<AtomicInteger>(); var keyRef = new AtomicReference<String>(null); var waitingForComma = new AtomicBoolean(false); PojoGetter.of(reference, value.getterProxy()) // .shallowly(true) // .walker((indicator, val, signature, proxy) -> { switch (indicator) { case START_MAP: case START_ARRAY: tryWriteComma(writer, waitingForComma); tryWriteWaitingKey(writer, keyRef); writer.writeByte(indicator == START_ARRAY ? JsonWriter.ARRAY_START : JsonWriter.OBJECT_START); waitingForComma.set(false); lengthStack.push((int) val); indexStack.push(new AtomicInteger(0)); if (indexStack.size() > 0) indexStack.peek().incrementAndGet(); break; case END_MAP: case END_ARRAY: indexStack.pop(); lengthStack.pop(); writer.writeByte(indicator == END_ARRAY ? JsonWriter.ARRAY_END : JsonWriter.OBJECT_END); waitingForComma.set(true); break; case KEY: keyRef.set((String) val); break; case KEY_NULL: indexStack.peek().incrementAndGet(); break; case VALUE: tryWriteComma(writer, waitingForComma); tryWriteWaitingKey(writer, keyRef); var ele = BElement.wrapAny(val); if (ele.isReference()) ele.asReference().getterProxy(proxy); writer.serializeObject(ele); indexStack.peek().incrementAndGet(); waitingForComma.set(true); break; } }) // .walk(); }
Example 11
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()); }