@Test public void writeString() throws IOException { inputFieldJsonWriter.writeString("someField", "someValue"); inputFieldJsonWriter.writeString("someNullField", null); assertThat(jsonBuffer.readUtf8()).isEqualTo("{\"someField\":\"someValue\",\"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(); } }
@Override public void writeCustom(@Nonnull String fieldName, ScalarType scalarType, Object value) throws IOException { checkNotNull(fieldName, "fieldName == null"); if (value != null) { CustomTypeAdapter customTypeAdapter = scalarTypeAdapters.adapterFor(scalarType); writeString(fieldName, customTypeAdapter.encode(value)); } else { writeString(fieldName, null); } }
@Override public void writeCustom(@Nonnull String fieldName, ScalarType scalarType, Object value) throws IOException { checkNotNull(fieldName, "fieldName == null"); if (value != null) { CustomTypeAdapter customTypeAdapter = scalarTypeAdapters.adapterFor(scalarType); writeString(fieldName, customTypeAdapter.encode(value)); } else { writeString(fieldName, null); } }