@Test public void parserStringList() throws IOException, JsonFormatException { String json = "[\"\",\"s\",\"str\"]"; JsonPullParser parser = JsonPullParser.newParser(json); List<String> list = JsonParseUtil.parserStringList(parser); assertThat(list.size(), is(3)); assertThat(list.get(0), is("")); assertThat(list.get(1), is("s")); assertThat(list.get(2), is("str")); }
public static List<String> parserStringList(JsonPullParser parser) throws IOException, JsonFormatException { State eventType = parser.getEventType(); if (eventType == State.VALUE_NULL) { return null; } if (eventType != State.START_ARRAY) { throw new IllegalStateException("not started brace!"); } List<String> list = new ArrayList<String>(); while (parser.lookAhead() != State.END_ARRAY) { eventType = parser.getEventType(); if (eventType == State.VALUE_NULL) { list.add(null); } else if (eventType == State.VALUE_STRING) { list.add(parser.getValueString()); } else { throw new IllegalStateException("unexpected state. expected=VALUE_STRING, but get=" + eventType.toString()); } } parser.getEventType(); return list; }
JsonParseUtil { public static List<String> parserStringList(JsonPullParser parser) throws IOException, JsonFormatException { State eventType = parser.getEventType(); if (eventType == State.VALUE_NULL) { return null; } if (eventType != State.START_ARRAY) { throw new IllegalStateException("not started brace!"); } List<String> list = new ArrayList<String>(); while (parser.lookAhead() != State.END_ARRAY) { eventType = parser.getEventType(); if (eventType == State.VALUE_NULL) { list.add(null); } else if (eventType == State.VALUE_STRING) { list.add(parser.getValueString()); } else { throw new IllegalStateException("unexpected state. expected=VALUE_STRING, but get=" + eventType.toString()); } } parser.getEventType(); return list; } }
JsonParseUtil { public static List<String> parserStringList(JsonPullParser parser) throws IOException, JsonFormatException { State eventType = parser.getEventType(); if (eventType == State.VALUE_NULL) { return null; } if (eventType != State.START_ARRAY) { throw new IllegalStateException("not started brace!"); } List<String> list = new ArrayList<String>(); while (parser.lookAhead() != State.END_ARRAY) { eventType = parser.getEventType(); if (eventType == State.VALUE_NULL) { list.add(null); } else if (eventType == State.VALUE_STRING) { list.add(parser.getValueString()); } else { throw new IllegalStateException("unexpected state. expected=VALUE_STRING, but get=" + eventType.toString()); } } parser.getEventType(); return list; }  }
JsonParseUtil { public static List<String> parserStringList(JsonPullParser parser) throws IOException, JsonFormatException { State eventType = parser.getEventType(); if (eventType == State.VALUE_NULL) { return null; } if (eventType != State.START_ARRAY) { throw new IllegalStateException("not started brace!"); } List<String> list = new ArrayList<String>(); while (parser.lookAhead() != State.END_ARRAY) { eventType = parser.getEventType(); if (eventType == State.VALUE_NULL) { list.add(null); } else if (eventType == State.VALUE_STRING) { list.add(parser.getValueString()); } else { throw new IllegalStateException("unexpected state. expected=VALUE_STRING, but get=" + eventType.toString()); } } parser.getEventType(); return list; }  static Integer parserInteger(JsonPullParser parser); static Long parserLong(JsonPullParser parser); static Byte parserByte(JsonPullParser parser); static Short parserShort(JsonPullParser parser); static Boolean parserBoolean(JsonPullParser parser); static Character parserCharacter(JsonPullParser parser); static Double parserDouble(JsonPullParser parser); static Float parserFloat(JsonPullParser parser); static List<Integer> parserIntegerList(JsonPullParser parser); static List<Long> parserLongList(JsonPullParser parser); static List<Byte> parserByteList(JsonPullParser parser); static List<Short> parserShortList(JsonPullParser parser); static List<Boolean> parserBooleanList(JsonPullParser parser); static List<Character> parserCharacterList(JsonPullParser parser); static List<Double> parserDoubleList(JsonPullParser parser); static List<Float> parserFloatList(JsonPullParser parser); static List<String> parserStringList(JsonPullParser parser); static List<Date> parserDateList(JsonPullParser parser); static List<T> parserEnumList(JsonPullParser parser, Class<T> clazz); }
JsonParseUtil { public static List<String> parserStringList(JsonPullParser parser) throws IOException, JsonFormatException { State eventType = parser.getEventType(); if (eventType == State.VALUE_NULL) { return null; } if (eventType != State.START_ARRAY) { throw new IllegalStateException("not started brace!"); } List<String> list = new ArrayList<String>(); while (parser.lookAhead() != State.END_ARRAY) { eventType = parser.getEventType(); if (eventType == State.VALUE_NULL) { list.add(null); } else if (eventType == State.VALUE_STRING) { list.add(parser.getValueString()); } else { throw new IllegalStateException("unexpected state. expected=VALUE_STRING, but get=" + eventType.toString()); } } parser.getEventType(); return list; }  static Integer parserInteger(JsonPullParser parser); static Long parserLong(JsonPullParser parser); static Byte parserByte(JsonPullParser parser); static Short parserShort(JsonPullParser parser); static Boolean parserBoolean(JsonPullParser parser); static Character parserCharacter(JsonPullParser parser); static Double parserDouble(JsonPullParser parser); static Float parserFloat(JsonPullParser parser); static List<Integer> parserIntegerList(JsonPullParser parser); static List<Long> parserLongList(JsonPullParser parser); static List<Byte> parserByteList(JsonPullParser parser); static List<Short> parserShortList(JsonPullParser parser); static List<Boolean> parserBooleanList(JsonPullParser parser); static List<Character> parserCharacterList(JsonPullParser parser); static List<Double> parserDoubleList(JsonPullParser parser); static List<Float> parserFloatList(JsonPullParser parser); static List<String> parserStringList(JsonPullParser parser); static List<Date> parserDateList(JsonPullParser parser); static List<T> parserEnumList(JsonPullParser parser, Class<T> clazz);  }