@Override public void didResolveList(List array) { try { jsonWriter.endArray(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void writeList(ListWriter listWriter) throws IOException { if (listWriter == null) { jsonWriter.nullValue(); } else { jsonWriter.beginArray(); listWriter.write(new JsonListItemWriter(jsonWriter, scalarTypeAdapters)); jsonWriter.endArray(); } } }
@Override public void writeList(@NotNull String fieldName, ListWriter listWriter) throws IOException { checkNotNull(fieldName, "fieldName == null"); if (listWriter != null) { jsonWriter.name(fieldName).beginArray(); listWriter.write(new JsonListItemWriter(jsonWriter, scalarTypeAdapters)); jsonWriter.endArray(); } else { jsonWriter.name(fieldName).nullValue(); } }
@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<Object, Object> entry : ((Map<Object, Object>) value).entrySet()) { String key = entry.getKey().toString(); jsonWriter.name(key); writeToJson(entry.getValue(), jsonWriter); } jsonWriter.endObject(); } else if (value instanceof List) { jsonWriter.beginArray(); for (Object item : (List) value) { writeToJson(item, jsonWriter); } jsonWriter.endArray(); } else if (value instanceof Boolean) { jsonWriter.value((Boolean) value); } else if (value instanceof Number) { jsonWriter.value((Number) value); } else { jsonWriter.value(value.toString()); } }
writeJsonValue(item, jsonWriter); jsonWriter.endArray(); } else if (value instanceof Map) {
@Override public void writeList(@Nonnull String fieldName, ListWriter listWriter) throws IOException { checkNotNull(fieldName, "fieldName == null"); if (listWriter != null) { jsonWriter.name(fieldName).beginArray(); listWriter.write(new JsonListItemWriter(jsonWriter, scalarTypeAdapters)); jsonWriter.endArray(); } else { jsonWriter.name(fieldName).nullValue(); } }
@Override public void writeList(@Nonnull String fieldName, ListWriter listWriter) throws IOException { checkNotNull(fieldName, "fieldName == null"); if (listWriter != null) { jsonWriter.name(fieldName).beginArray(); listWriter.write(new JsonListItemWriter(jsonWriter, scalarTypeAdapters)); jsonWriter.endArray(); } else { jsonWriter.name(fieldName).nullValue(); } }
private static void writeJsonValue(Object value, JsonWriter jsonWriter) throws IOException { if (value == null) { jsonWriter.nullValue(); } else if (value instanceof String) { jsonWriter.value((String) value); } else if (value instanceof Boolean) { jsonWriter.value((boolean) value); } else if (value instanceof Number) { jsonWriter.value((Number) value); } else if (value instanceof CacheReference) { jsonWriter.value(((CacheReference) value).serialize()); } else if (value instanceof List) { jsonWriter.beginArray(); for (Object item : (List) value) { writeJsonValue(item, jsonWriter); } jsonWriter.endArray(); } else { throw new RuntimeException("Unsupported record value type: " + value.getClass()); } } }
private static void writeJsonValue(Object value, JsonWriter jsonWriter) throws IOException { if (value == null) { jsonWriter.nullValue(); } else if (value instanceof String) { jsonWriter.value((String) value); } else if (value instanceof Boolean) { jsonWriter.value((boolean) value); } else if (value instanceof Number) { jsonWriter.value((Number) value); } else if (value instanceof CacheReference) { jsonWriter.value(((CacheReference) value).serialize()); } else if (value instanceof List) { jsonWriter.beginArray(); for (Object item : (List) value) { writeJsonValue(item, jsonWriter); } jsonWriter.endArray(); } else { throw new RuntimeException("Unsupported record value type: " + value.getClass()); } } }