JsonParseUtil { public static Integer parserInteger(JsonPullParser parser) throws IOException, JsonFormatException { State eventType = parser.getEventType(); if (eventType == State.VALUE_NULL) { return null; } else if (eventType == State.VALUE_LONG) { return (int) parser.getValueLong(); } else { throw new IllegalStateException("unexpected state. expected=VALUE_LONG, but get=" + eventType.toString()); } }  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);  }
@Test public void parserInteger() throws IOException, JsonFormatException { String json = "[0,null,2,3,4]"; JsonPullParser parser = JsonPullParser.newParser(json); State state = parser.getEventType(); assertThat(state, is(State.START_ARRAY)); assertThat(JsonParseUtil.parserInteger(parser), is(0)); assertThat(JsonParseUtil.parserInteger(parser), nullValue()); assertThat(JsonParseUtil.parserInteger(parser), is(2)); assertThat(JsonParseUtil.parserInteger(parser), is(3)); assertThat(JsonParseUtil.parserInteger(parser), is(4)); }