List of usage examples for com.google.gson.stream JsonToken BEGIN_OBJECT
JsonToken BEGIN_OBJECT
To view the source code for com.google.gson.stream JsonToken BEGIN_OBJECT.
Click Source Link
From source file:se.sics.datamodel.gson.TypeInfoAdapter.java
License:Open Source License
@Override public TypeInfo read(JsonReader reader) throws IOException { String typeName;/*w ww . j av a 2 s .c om*/ Gson gson = GsonHelper.getGson(); reader.beginObject(); if (reader.peek() != JsonToken.NAME || !reader.nextName().equals("typeName")) { throw new IOException(); } typeName = reader.nextString(); if (reader.peek() != JsonToken.NAME || !reader.nextName().equals("fieldMap")) { throw new IOException(); } if (reader.peek() != JsonToken.BEGIN_ARRAY) { throw new IOException(); } reader.beginArray(); TypeInfo.Builder tiBuilder = new TypeInfo.Builder(typeName); while (reader.peek() != JsonToken.END_ARRAY) { if (reader.peek() != JsonToken.BEGIN_OBJECT) { throw new IOException(); } reader.beginObject(); if (reader.peek() != JsonToken.NAME || !reader.nextName().equals("id")) { throw new IOException(); } ByteId fieldId = new ByteId((byte[]) gson.fromJson(reader, byte[].class)); if (reader.peek() != JsonToken.NAME || !reader.nextName().equals("field")) { throw new IOException(); } FieldInfo fieldInfo = gson.fromJson(reader, FieldInfo.class); tiBuilder.put(fieldId, fieldInfo); reader.endObject(); } reader.endArray(); reader.endObject(); return tiBuilder.build(); }
From source file:se.sics.datamodel.gson.ValueHolderAdapter.java
License:Open Source License
@Override public ValueHolder read(JsonReader reader) throws IOException { Gson gson = GsonHelper.getGson();//from w w w . j a va2 s.c om ValueHolder.Builder vhBuilder = new ValueHolder.Builder(); if (reader.peek() != JsonToken.BEGIN_OBJECT) { throw new IOException(); } reader.beginObject(); if (reader.peek() != JsonToken.NAME || !reader.nextName().equals("fieldMap")) { throw new IOException(); } if (reader.peek() != JsonToken.BEGIN_ARRAY) { throw new IOException(); } reader.beginArray(); while (reader.peek() != JsonToken.END_ARRAY) { if (reader.peek() != JsonToken.BEGIN_OBJECT) { throw new IOException(); } reader.beginObject(); if (reader.peek() != JsonToken.NAME || !reader.nextName().equals("id")) { throw new IOException(); } ByteId fieldId = new ByteId((byte[]) gson.fromJson(reader, byte[].class)); if (reader.peek() != JsonToken.NAME || !reader.nextName().equals("field")) { throw new IOException(); } JsonElement je = gson.fromJson(reader, JsonElement.class); vhBuilder.put(fieldId, je); if (reader.peek() != JsonToken.END_OBJECT) { throw new IOException(); } reader.endObject(); } reader.endArray(); reader.endObject(); return vhBuilder.build(); }
From source file:teste.adapter.ArrayAdapter.java
public List<T> read(JsonReader reader) throws IOException { List<T> list = new ArrayList<T>(); Gson gson = new GsonBuilder().registerTypeAdapterFactory(new ArrayAdapterFactory()).create(); if (reader.peek() == JsonToken.BEGIN_OBJECT) { T inning = gson.fromJson(reader, adapterclass); list.add(inning);// w w w . ja v a2 s . c o m } else if (reader.peek() == JsonToken.BEGIN_ARRAY) { reader.beginArray(); while (reader.hasNext()) { T inning = gson.fromJson(reader, adapterclass); list.add(inning); } reader.endArray(); } return list; }
From source file:util.android.gson.ArrayAdapter.java
License:Apache License
@Override public List<T> read(JsonReader reader) throws IOException { List<T> list = new ArrayList<T>(); Gson gson = new GsonBuilder().registerTypeAdapterFactory(new ArrayAdapterFactory()).create(); if (reader.peek() == JsonToken.BEGIN_OBJECT) { T inning = gson.fromJson(reader, adapterclass); list.add(inning);/*from ww w .ja va2 s. co m*/ } else if (reader.peek() == JsonToken.BEGIN_ARRAY) { reader.beginArray(); while (reader.hasNext()) { T inning = gson.fromJson(reader, adapterclass); list.add(inning); } reader.endArray(); } return list; }