@Test public void writeNumber() throws IOException { inputFieldJsonWriter.writeNumber("someField", BigDecimal.valueOf(1.001)); inputFieldJsonWriter.writeNumber("someNullField", null); assertThat(jsonBuffer.readUtf8()).isEqualTo("{\"someField\":1.001,\"someNullField\":null"); }
@SuppressWarnings("unchecked") @Override public void writeCustom(@NotNull String fieldName, ScalarType scalarType, Object value) throws IOException { checkNotNull(fieldName, "fieldName == null"); if (value != null) { CustomTypeAdapter customTypeAdapter = scalarTypeAdapters.adapterFor(scalarType); CustomTypeValue customTypeValue = customTypeAdapter.encode(value); if (customTypeValue instanceof CustomTypeValue.GraphQLString) { writeString(fieldName, ((CustomTypeValue.GraphQLString) customTypeValue).value); } else if (customTypeValue instanceof CustomTypeValue.GraphQLBoolean) { writeBoolean(fieldName, ((CustomTypeValue.GraphQLBoolean) customTypeValue).value); } else if (customTypeValue instanceof CustomTypeValue.GraphQLNumber) { writeNumber(fieldName, ((CustomTypeValue.GraphQLNumber) customTypeValue).value); } else if (customTypeValue instanceof CustomTypeValue.GraphQLJsonString) { writeString(fieldName, ((CustomTypeValue.GraphQLJsonString) customTypeValue).value); } else if (customTypeValue instanceof CustomTypeValue.GraphQLJson) { writeMap(fieldName, ((CustomTypeValue.GraphQLJson) customTypeValue).value); } else { throw new IllegalArgumentException("Unsupported custom value type: " + customTypeValue); } } else { jsonWriter.name(fieldName).nullValue(); } }