@SuppressWarnings("unchecked") @Override public void write(JsonWriter out, Object array) throws IOException { if (array == null) { out.nullValue(); return; } out.beginArray(); for (int i = 0, length = Array.getLength(array); i < length; i++) { E value = (E) Array.get(array, i); componentTypeAdapter.write(out, value); } out.endArray(); }
public Object read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull(); return null; } List<E> list = new ArrayList<E>(); in.beginArray(); while (in.hasNext()) { E instance = componentTypeAdapter.read(in); list.add(instance); } in.endArray(); Object array = Array.newInstance(componentType, list.size()); for (int i = 0; i < list.size(); i++) { Array.set(array, i, list.get(i)); } return array; }