@Override public boolean[] fromJson(final JsonReader jsonReader) throws IOException { jsonReader.assertRead('['); final ArrayList<Boolean> values = new ArrayList<Boolean>(); boolean needComma = false; while (jsonReader.read() != ']') { if (needComma) { jsonReader.assertLast(','); jsonReader.next(); } final char ch = jsonReader.read(); if (ch == 't') values.add(jsonReader.readTrue()); else if (ch == 'f') values.add(jsonReader.readFalse()); else throw new IOException( "Could not parse boolean, expected 'true' or 'false', but token begins with '" + ch + "'"); needComma = true; } jsonReader.invalidate(); final boolean[] result = new boolean[values.size()]; for (int i = 0; i < result.length; i++) { result[i] = values.get(i); } return result; }
@Override public int[] fromJson(final JsonReader jsonReader) throws IOException { jsonReader.assertRead('['); final StringBuilder sb = new StringBuilder(); final ArrayList<String> values = new ArrayList<String>(); boolean needComma = false; while (jsonReader.read() != ']') { if (needComma) { jsonReader.assertLast(','); sb.setLength(0); jsonReader.next(); } values.add(jsonReader.readRawNumber(sb).toString()); needComma = true; } jsonReader.invalidate(); final int[] result = new int[values.size()]; for (int i = 0; i < result.length; i++) { result[i] = (int) Double.parseDouble(values.get(i)); } return result; }