Tabnine Logo
InputFieldJsonWriter
Code IndexAdd Tabnine to your IDE (free)

How to use
InputFieldJsonWriter
in
com.apollographql.apollo.internal.json

Best Java code snippets using com.apollographql.apollo.internal.json.InputFieldJsonWriter (Showing top 20 results out of 315)

origin: apollographql/apollo-android

@Override public void writeObject(InputFieldMarshaller marshaller) throws IOException {
 if (marshaller == null) {
  jsonWriter.nullValue();
 } else {
  jsonWriter.beginObject();
  marshaller.marshal(new InputFieldJsonWriter(jsonWriter, scalarTypeAdapters));
  jsonWriter.endObject();
 }
}
origin: apollographql/apollo-android

@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();
 }
}
origin: apollographql/apollo-android

@Test
public void writeCustomNumber() throws IOException {
 Map<ScalarType, CustomTypeAdapter> customTypeAdapters = new HashMap<>();
 customTypeAdapters.put(new MockCustomScalarType(CustomTypeValue.GraphQLNumber.class), new MockCustomTypeAdapter() {
  @NotNull @Override public CustomTypeValue encode(@NotNull Object value) {
   return new CustomTypeValue.GraphQLNumber((Number) value);
  }
 });
 inputFieldJsonWriter = new InputFieldJsonWriter(jsonWriter, new ScalarTypeAdapters(customTypeAdapters));
 inputFieldJsonWriter.writeCustom("someField", new MockCustomScalarType(CustomTypeValue.GraphQLNumber.class), BigDecimal.valueOf(100.1));
 inputFieldJsonWriter.writeCustom("someNullField", new MockCustomScalarType(CustomTypeValue.GraphQLNumber.class), null);
 assertThat(jsonBuffer.readUtf8()).isEqualTo("{\"someField\":100.1,\"someNullField\":null");
}
origin: apollographql/apollo-android

@Test
public void writeString() throws IOException {
 inputFieldJsonWriter.writeString("someField", "someValue");
 inputFieldJsonWriter.writeString("someNullField", null);
 assertThat(jsonBuffer.readUtf8()).isEqualTo("{\"someField\":\"someValue\",\"someNullField\":null");
}
origin: apollographql/apollo-android

@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");
}
origin: apollographql/apollo-android

@Test
public void writeBoolean() throws IOException {
 inputFieldJsonWriter.writeBoolean("someField", true);
 inputFieldJsonWriter.writeBoolean("someNullField", null);
 assertThat(jsonBuffer.readUtf8()).isEqualTo("{\"someField\":true,\"someNullField\":null");
}
origin: apollographql/apollo-android

@Test
public void writeDouble() throws IOException {
 inputFieldJsonWriter.writeDouble("someField", 1.01);
 inputFieldJsonWriter.writeDouble("someNullField", null);
 assertThat(jsonBuffer.readUtf8()).isEqualTo("{\"someField\":1.01,\"someNullField\":null");
}
origin: awslabs/aws-mobile-appsync-sdk-android

@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);
 }
}
origin: apollographql/apollo-android

@Before
public void setUp() throws IOException {
 jsonBuffer = new Buffer();
 jsonWriter = JsonWriter.of(jsonBuffer);
 jsonWriter.setSerializeNulls(true);
 jsonWriter.beginObject();
 inputFieldJsonWriter = new InputFieldJsonWriter(jsonWriter,
   new ScalarTypeAdapters(Collections.<ScalarType, CustomTypeAdapter>emptyMap()));
}
origin: apollographql/apollo-android

@Test
public void writeCustomString() throws IOException {
 Map<ScalarType, CustomTypeAdapter> customTypeAdapters = new HashMap<>();
 customTypeAdapters.put(new MockCustomScalarType(CustomTypeValue.GraphQLString.class), new MockCustomTypeAdapter() {
  @NotNull @Override public CustomTypeValue encode(@NotNull Object value) {
   return new CustomTypeValue.GraphQLString((String) value);
  }
 });
 inputFieldJsonWriter = new InputFieldJsonWriter(jsonWriter, new ScalarTypeAdapters(customTypeAdapters));
 inputFieldJsonWriter.writeCustom("someField", new MockCustomScalarType(CustomTypeValue.GraphQLString.class), "someValue");
 inputFieldJsonWriter.writeCustom("someNullField", new MockCustomScalarType(CustomTypeValue.GraphQLString.class), null);
 assertThat(jsonBuffer.readUtf8()).isEqualTo("{\"someField\":\"someValue\",\"someNullField\":null");
}
origin: com.amazonaws/aws-android-sdk-appsync-runtime

@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);
 }
}
origin: apollographql/apollo-android

 @Override public void writeToJson(@NotNull JsonWriter writer) throws IOException {
  checkNotNull(writer, "writer == null");
  writer.name(JSON_KEY_ID).value(subscriptionId);
  writer.name(JSON_KEY_TYPE).value(TYPE);
  writer.name(JSON_KEY_PAYLOAD).beginObject();
  writer.name(JSON_KEY_QUERY).value(subscription.queryDocument().replaceAll("\\n", ""));
  writer.name(JSON_KEY_VARIABLES).beginObject();
  subscription.variables().marshaller().marshal(new InputFieldJsonWriter(writer, scalarTypeAdapters));
  writer.endObject();
  writer.name(JSON_KEY_OPERATION_NAME).value(subscription.name().name());
  writer.endObject();
 }
}
origin: apollographql/apollo-android

@Test
public void writeCustomBoolean() throws IOException {
 Map<ScalarType, CustomTypeAdapter> customTypeAdapters = new HashMap<>();
 customTypeAdapters.put(new MockCustomScalarType(CustomTypeValue.GraphQLBoolean.class), new MockCustomTypeAdapter() {
  @NotNull @Override public CustomTypeValue encode(@NotNull Object value) {
   return new CustomTypeValue.GraphQLBoolean((Boolean) value);
  }
 });
 inputFieldJsonWriter = new InputFieldJsonWriter(jsonWriter, new ScalarTypeAdapters(customTypeAdapters));
 inputFieldJsonWriter.writeCustom("someField", new MockCustomScalarType(CustomTypeValue.GraphQLBoolean.class), true);
 inputFieldJsonWriter.writeCustom("someNullField", new MockCustomScalarType(CustomTypeValue.GraphQLBoolean.class), null);
 assertThat(jsonBuffer.readUtf8()).isEqualTo("{\"someField\":true,\"someNullField\":null");
}
origin: apollographql/apollo-android

 static ByteString httpRequestBody(Operation operation, ScalarTypeAdapters scalarTypeAdapters,
   boolean writeQueryDocument) throws IOException {
  Buffer buffer = new Buffer();
  JsonWriter jsonWriter = JsonWriter.of(buffer);
  jsonWriter.setSerializeNulls(true);
  jsonWriter.beginObject();
  jsonWriter.name("operationName").value(operation.name().name());
  jsonWriter.name("variables").beginObject();
  operation.variables().marshaller().marshal(new InputFieldJsonWriter(jsonWriter, scalarTypeAdapters));
  jsonWriter.endObject();
  jsonWriter.name("extensions")
    .beginObject()
    .name("persistedQuery")
    .beginObject()
    .name("version").value(1)
    .name("sha256Hash").value(operation.operationId())
    .endObject()
    .endObject();
  if (writeQueryDocument) {
   jsonWriter.name("query").value(operation.queryDocument().replaceAll("\\n", ""));
  }
  jsonWriter.endObject();
  jsonWriter.close();
  return buffer.readByteString();
 }
}
origin: apollographql/apollo-android

@Test
public void writeCustomJsonString() throws IOException {
 Map<ScalarType, CustomTypeAdapter> customTypeAdapters = new HashMap<>();
 customTypeAdapters.put(new MockCustomScalarType(CustomTypeValue.GraphQLJsonString.class), new MockCustomTypeAdapter() {
  @NotNull @Override public CustomTypeValue encode(@NotNull Object value) {
   return new CustomTypeValue.GraphQLJsonString((String) value);
  }
 });
 inputFieldJsonWriter = new InputFieldJsonWriter(jsonWriter, new ScalarTypeAdapters(customTypeAdapters));
 inputFieldJsonWriter.writeCustom("someField", new MockCustomScalarType(CustomTypeValue.GraphQLJsonString.class), "{\"someField\": \"someValue\"}");
 inputFieldJsonWriter.writeCustom("someNullField", new MockCustomScalarType(CustomTypeValue.GraphQLJsonString.class), null);
 assertThat(jsonBuffer.readUtf8()).isEqualTo("{\"someField\":\"{\\\"someField\\\": \\\"someValue\\\"}\",\"someNullField\":null");
}
origin: com.amazonaws/aws-android-sdk-appsync-runtime

 @Override public void writeObject(InputFieldMarshaller marshaller) throws IOException {
  if (marshaller != null) {
   jsonWriter.beginObject();
   marshaller.marshal(new InputFieldJsonWriter(jsonWriter, scalarTypeAdapters));
   jsonWriter.endObject();
  }
 }
}
origin: apollographql/apollo-android

@Test
public void writeCustomJson() throws IOException {
 Map<ScalarType, CustomTypeAdapter> customTypeAdapters = new HashMap<>();
 customTypeAdapters.put(new MockCustomScalarType(CustomTypeValue.GraphQLJson.class), new MockCustomTypeAdapter() {
  @NotNull @Override public CustomTypeValue encode(@NotNull Object value) {
   return new CustomTypeValue.GraphQLJson((Map<String, Object>) value);
  }
 });
 inputFieldJsonWriter = new InputFieldJsonWriter(jsonWriter, new ScalarTypeAdapters(customTypeAdapters));
 Map<String, Object> objectMap = new LinkedHashMap<>();
 objectMap.put("booleanField", true);
 objectMap.put("stringField", "someValue");
 objectMap.put("numberField", 100);
 objectMap.put("objectField", new UnmodifiableMapBuilder().put("someField", "someValue").build());
 inputFieldJsonWriter.writeCustom("someField", new MockCustomScalarType(CustomTypeValue.GraphQLJson.class), objectMap);
 inputFieldJsonWriter.writeCustom("someNullField", new MockCustomScalarType(CustomTypeValue.GraphQLJson.class), null);
 assertThat(jsonBuffer.readUtf8()).isEqualTo("{\"someField\":{\"booleanField\":true,\"stringField\":\"someValue\",\"numberField\":100,\"objectField\":{\"someField\":\"someValue\"}},\"someNullField\":null");
}
origin: awslabs/aws-mobile-appsync-sdk-android

 @Override public void writeObject(InputFieldMarshaller marshaller) throws IOException {
  if (marshaller != null) {
   jsonWriter.beginObject();
   marshaller.marshal(new InputFieldJsonWriter(jsonWriter, scalarTypeAdapters));
   jsonWriter.endObject();
  }
 }
}
origin: awslabs/aws-mobile-appsync-sdk-android

private String httpRequestBody(Operation operation) throws IOException {
  Buffer buffer = new Buffer();
  JsonWriter jsonWriter = JsonWriter.of(buffer);
  jsonWriter.beginObject();
  jsonWriter.name("query").value(operation.queryDocument().replaceAll("\\n", ""));
  jsonWriter.name("variables").beginObject();
  operation.variables().marshaller().marshal(new InputFieldJsonWriter(jsonWriter, scalarTypeAdapters));
  jsonWriter.endObject();
  jsonWriter.endObject();
  jsonWriter.close();
  return buffer.readUtf8();
}
origin: awslabs/aws-mobile-appsync-sdk-android

private RequestBody httpRequestBody(Operation operation) throws IOException {
 Buffer buffer = new Buffer();
 JsonWriter jsonWriter = JsonWriter.of(buffer);
 jsonWriter.beginObject();
 if (sendOperationIdentifiers) {
  jsonWriter.name("id").value(operation.operationId());
 } else {
  jsonWriter.name("query").value(operation.queryDocument().replaceAll("\\n", ""));
 }
 jsonWriter.name("variables").beginObject();
 operation.variables().marshaller().marshal(new InputFieldJsonWriter(jsonWriter, scalarTypeAdapters));
 jsonWriter.endObject();
 jsonWriter.endObject();
 jsonWriter.close();
 return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
com.apollographql.apollo.internal.jsonInputFieldJsonWriter

Most used methods

  • <init>
  • writeString
  • writeBoolean
  • writeNumber
  • writeCustom
  • writeDouble
  • writeInt
  • writeList
  • writeLong
  • writeMap
  • writeObject
  • writeObject

Popular in Java

  • Creating JSON documents from java classes using gson
  • getResourceAsStream (ClassLoader)
  • findViewById (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • Option (scala)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now