com.apollographql.apollo.internal.json.Utils Maven / Gradle / Ivy
/**
* Copyright 2018-2019 Amazon.com,
* Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: Apache-2.0
*/
package com.apollographql.apollo.internal.json;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
import okio.Buffer;
import static com.apollographql.apollo.api.internal.Utils.checkNotNull;
public final class Utils {
public static String toJsonString(@Nonnull Object data) throws IOException {
checkNotNull(data, "data == null");
Buffer buffer = new Buffer();
JsonWriter jsonWriter = JsonWriter.of(buffer);
writeToJson(data, jsonWriter);
jsonWriter.close();
return buffer.readUtf8();
}
@SuppressWarnings("unchecked")
public static void writeToJson(Object value, JsonWriter jsonWriter) throws IOException {
if (value == null) {
jsonWriter.nullValue();
} else if (value instanceof Map) {
jsonWriter.beginObject();
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy