@Override public void toJson(JsonWriter writer, String value) throws IOException { writer.value(value); }
@Override public void toJson(JsonWriter writer, Float value) throws IOException { // Manual null pointer check for the float.class adapter. if (value == null) { throw new NullPointerException(); } // Use the Number overload so we write out float precision instead of double precision. writer.value(value); }
@Override public void toJson(JsonWriter writer, Double value) throws IOException { writer.value(value.doubleValue()); }
@Override public void toJson(JsonWriter writer, T value) throws IOException { writer.value(nameStrings[value.ordinal()]); }
@Override public void toJson(JsonWriter writer, Long value) throws IOException { writer.value(value.longValue()); }
@Override public void toJson(JsonWriter writer, T value) throws IOException { writer.value(nameStrings[value.ordinal()]); }
@Override public void toJson(JsonWriter writer, Character value) throws IOException { writer.value(value.toString()); }
@Override public void toJson(JsonWriter writer, Byte value) throws IOException { writer.value(value.intValue() & 0xff); }
@Override public void toJson(JsonWriter writer, Integer value) throws IOException { writer.value(value.intValue()); }
@Override public void toJson(JsonWriter writer, Short value) throws IOException { writer.value(value.intValue()); }
@Override public void toJson(JsonWriter writer, Boolean value) throws IOException { writer.value(value.booleanValue()); }
@Override public void toJson(JsonWriter writer, T value) throws IOException { if (value == null) { throw new NullPointerException( "value was null! Wrap in .nullSafe() to write nullable values."); } writer.value(nameStrings[value.ordinal()]); }
@Override public void toJson(JsonWriter writer, ByteString value) throws IOException { String string = value.base64(); writer.value(string); } }
@Override public synchronized void toJson(JsonWriter writer, Date value) throws IOException { String string = Iso8601Utils.format(value); writer.value(string); } }
@Override public void toJson(JsonWriter out, ByteString byteString) throws IOException { out.value(byteString.base64()); }
@Override public void toJson(JsonWriter writer, Object value) throws IOException { Class<?> type = value.getClass(); int labelIndex = subtypes.indexOf(type); if (labelIndex == -1) { throw new IllegalArgumentException("Expected one of " + subtypes + " but found " + value + ", a " + value.getClass() + ". Register this subtype."); } JsonAdapter<Object> adapter = jsonAdapters.get(labelIndex); writer.beginObject(); writer.name(labelKey).value(labels.get(labelIndex)); int flattenToken = writer.beginFlatten(); adapter.toJson(writer, value); writer.endFlatten(flattenToken); writer.endObject(); }
/** * Generates a dummy package.json file to silence npm warnings */ private void writePackageFile(File apolloPackageFile) { try { JsonWriter writer = JsonWriter.of(Okio.buffer(Okio.sink(apolloPackageFile))); writer.beginObject(); writer.name("name").value("apollo-android"); writer.name("version").value("0.0.1"); writer.name("description").value("Generates Java code based on a GraphQL schema and query documents. Uses " + "apollo-codegen under the hood."); writer.name("name").value("apollo-android"); writer.name("repository"); writer.beginObject(); writer.name("type").value("git"); writer.name("url").value("git+https://github.com/apollostack/apollo-android.git"); writer.endObject(); writer.name("author").value("Apollo"); writer.name("license").value("MIT"); writer.endObject(); writer.close(); } catch (IOException e) { e.printStackTrace(); } }
private String createJsonObject(final Map<String, Object> parameterMap) throws IOException { Buffer b = new Buffer(); JsonWriter writer = JsonWriter.of(b); writer.beginObject(); for (Entry<String, Object> pair : parameterMap.entrySet()) { String name = pair.getKey(); Object value = pair.getValue(); if (value instanceof Number) { Number number = (Number) value; writer.name(name).value(number); } else if (value instanceof String) { writer.name(name).value((String) value); } else if (value instanceof Boolean) { writer.name(name).value((Boolean) value); } else { writer.name(name).value(String.valueOf(value)); } } writer.endObject(); return b.readString(Charset.forName("utf-8")); }
@Override public void toJson(com.squareup.moshi.JsonWriter writer, @Nullable BigDecimal value) throws IOException { writer.value(value.toPlainString()); } }).add(LocalDate.class, new JsonAdapter<LocalDate>() {