use of com.apollographql.apollo.internal.json.BufferedSourceJsonReader in project apollo-android by apollographql.
the class OperationResponseParser method parse.
public Response<W> parse(BufferedSource source) throws IOException {
responseNormalizer.willResolveRootQuery(operation);
BufferedSourceJsonReader jsonReader = null;
try {
jsonReader = new BufferedSourceJsonReader(source);
jsonReader.beginObject();
D data = null;
List<Error> errors = null;
ResponseJsonStreamReader responseStreamReader = responseJsonStreamReader(jsonReader);
while (responseStreamReader.hasNext()) {
String name = responseStreamReader.nextName();
if ("data".equals(name)) {
// noinspection unchecked
data = (D) responseStreamReader.nextObject(true, new ResponseJsonStreamReader.ObjectReader<Object>() {
@Override
public Object read(ResponseJsonStreamReader reader) throws IOException {
Map<String, Object> buffer = reader.toMap();
RealResponseReader<Map<String, Object>> realResponseReader = new RealResponseReader<>(operation.variables(), buffer, new MapFieldValueResolver(), scalarTypeAdapters, responseNormalizer);
return responseFieldMapper.map(realResponseReader);
}
});
} else if ("errors".equals(name)) {
errors = readResponseErrors(responseStreamReader);
} else {
responseStreamReader.skipNext();
}
}
jsonReader.endObject();
return Response.<W>builder(operation).data(operation.wrapData(data)).errors(errors).dependentKeys(responseNormalizer.dependentKeys()).build();
} finally {
if (jsonReader != null) {
jsonReader.close();
}
}
}
use of com.apollographql.apollo.internal.json.BufferedSourceJsonReader in project apollo-android by apollographql.
the class OperationServerMessage method fromJsonString.
@Nonnull
public static OperationServerMessage fromJsonString(@Nonnull String json) {
checkNotNull(json, "json == null");
try {
Buffer buffer = new Buffer();
buffer.writeUtf8(json);
return OperationServerMessage.readFromJson(new BufferedSourceJsonReader(buffer));
} catch (Exception e) {
return new Unsupported(json);
}
}
Aggregations