Java Code Examples for com.squareup.moshi.JsonReader#endArray()
The following examples show how to use
com.squareup.moshi.JsonReader#endArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HasMany.java From moshi-jsonapi with MIT License | 5 votes |
@Override public HasMany<T> fromJson(JsonReader reader) throws IOException { HasMany<T> relationship = new HasMany<>(); reader.beginObject(); while (reader.hasNext()) { switch (reader.nextName()) { case "data": if (reader.peek() == JsonReader.Token.NULL) { relationship.hasData = false; reader.nextNull(); } else { reader.beginArray(); while (reader.hasNext()) { relationship.add(resourceIdentifierJsonAdapter.fromJson(reader)); } reader.endArray(); } break; case "meta": relationship.setMeta(nextNullableObject(reader, jsonBufferJsonAdapter)); break; case "links": relationship.setLinks(nextNullableObject(reader, jsonBufferJsonAdapter)); break; default: reader.skipValue(); break; } } reader.endObject(); return relationship; }
Example 2
Source File: ModelListAdapter.java From android with Apache License 2.0 | 5 votes |
@Override public List<T> fromJson(JsonReader reader) throws IOException { List<T> nations = new ArrayList<>(); reader.beginObject(); reader.nextName(); reader.beginArray(); while (reader.peek() == JsonReader.Token.BEGIN_OBJECT) { nations.add(moshi.adapter(type).fromJson(reader)); } reader.endArray(); reader.endObject(); return nations; }
Example 3
Source File: CustomAdapterFactory.java From moshi with Apache License 2.0 | 5 votes |
@Override public SortedSet<T> fromJson(JsonReader reader) throws IOException { TreeSet<T> result = new TreeSet<>(); reader.beginArray(); while (reader.hasNext()) { result.add(elementAdapter.fromJson(reader)); } reader.endArray(); return result; }
Example 4
Source File: MoshiHelper.java From moshi-jsonapi with MIT License | 4 votes |
public static void dump(JsonReader reader, JsonWriter writer) throws IOException { int nested = 0; boolean nullFlag = writer.getSerializeNulls(); writer.setSerializeNulls(true); try { while (reader.peek() != JsonReader.Token.END_DOCUMENT) { switch (reader.peek()) { case BEGIN_ARRAY: nested++; reader.beginArray(); writer.beginArray(); break; case END_ARRAY: reader.endArray(); writer.endArray(); if (0 == --nested) return; break; case BEGIN_OBJECT: nested++; reader.beginObject(); writer.beginObject(); break; case END_OBJECT: reader.endObject(); writer.endObject(); if (0 == --nested) return; break; case NAME: writer.name(reader.nextName()); break; case NUMBER: Double doubleValue = reader.nextDouble(); if (Math.floor(doubleValue) == doubleValue) { writer.value(doubleValue.longValue()); } else { writer.value(doubleValue); } break; case BOOLEAN: writer.value(reader.nextBoolean()); break; case STRING: writer.value(reader.nextString()); break; case NULL: reader.nextNull(); writer.nullValue(); break; } } } finally { writer.setSerializeNulls(nullFlag); } }