@Test public void parseEmpty() throws IOException, JsonFormatException { String json = "{}"; JsonPullParser parser = JsonPullParser.newParser(json); JsonHash jsonHash = JsonHash.fromParser(parser); assertThat(jsonHash.size(), is(0)); }
public static JsonHash fromParser(JsonPullParser parser) throws IOException, JsonFormatException { State state = parser.getEventType(); if (state == State.VALUE_NULL) { return null; } else if (state != State.START_HASH) { throw new JsonFormatException("unexpected token. token=" + state, parser); } JsonHash jsonHash = new JsonHash(); while ((state = parser.lookAhead()) != State.END_HASH) { state = parser.getEventType(); if (state != State.KEY) { throw new JsonFormatException("unexpected token. token=" + state, parser); } String key = parser.getValueString(); state = parser.lookAhead(); jsonHash.put(key, getValue(parser), state); } parser.getEventType(); return jsonHash; }
JsonHash extends LinkedHashMap<String, Object> { public static JsonHash fromParser(JsonPullParser parser) throws IOException, JsonFormatException { State state = parser.getEventType(); if (state == State.VALUE_NULL) { return null; } else if (state != State.START_HASH) { throw new JsonFormatException("unexpected token. token=" + state, parser); } JsonHash jsonHash = new JsonHash(); while ((state = parser.lookAhead()) != State.END_HASH) { state = parser.getEventType(); if (state != State.KEY) { throw new JsonFormatException("unexpected token. token=" + state, parser); } String key = parser.getValueString(); state = parser.lookAhead(); jsonHash.put(key, getValue(parser), state); } parser.getEventType(); return jsonHash; } }
JsonHash extends LinkedHashMap<String, Object> { public static JsonHash fromParser(JsonPullParser parser) throws IOException, JsonFormatException { State state = parser.getEventType(); if (state == State.VALUE_NULL) { return null; } else if (state != State.START_HASH) { throw new JsonFormatException("unexpected token. token=" + state, parser); } JsonHash jsonHash = new JsonHash(); while ((state = parser.lookAhead()) != State.END_HASH) { state = parser.getEventType(); if (state != State.KEY) { throw new JsonFormatException("unexpected token. token=" + state, parser); } String key = parser.getValueString(); state = parser.lookAhead(); jsonHash.put(key, getValue(parser), state); } parser.getEventType(); return jsonHash; }  }
JsonHash extends LinkedHashMap<String, Object> { public static JsonHash fromParser(JsonPullParser parser) throws IOException, JsonFormatException { State state = parser.getEventType(); if (state == State.VALUE_NULL) { return null; } else if (state != State.START_HASH) { throw new JsonFormatException("unexpected token. token=" + state, parser); } JsonHash jsonHash = new JsonHash(); while ((state = parser.lookAhead()) != State.END_HASH) { state = parser.getEventType(); if (state != State.KEY) { throw new JsonFormatException("unexpected token. token=" + state, parser); } String key = parser.getValueString(); state = parser.lookAhead(); jsonHash.put(key, getValue(parser), state); } parser.getEventType(); return jsonHash; }  static JsonHash fromString(String json); static JsonHash fromParser(JsonPullParser parser); void toJson(Writer writer); @Override void clear(); @Override Object clone(); @Deprecated State getState(String key); Type getType(String key); Boolean getBooleanOrNull(String key); String getStringOrNull(String key); Long getLongOrNull(String key); Double getDoubleOrNull(String key); JsonHash getJsonHashOrNull(String key); JsonArray getJsonArrayOrNull(String key); @Deprecated Object put(String key, Object value, State state); Object put(String key, Object value, Type type); Object put(String key, String value); Object put(String key, Boolean value); Object put(String key, Double value); Object put(String key, Float value); Object put(String key, Byte value); Object put(String key, Short value); Object put(String key, Integer value); Object put(String key, Long value); Object put(String key, JsonArray value); Object put(String key, JsonHash value); @Override Object put(String key, Object value); @Override void putAll(Map<? extends String, ? extends Object> map); @Override Object remove(Object obj); @Override boolean equals(Object obj); @Override String toString(); }
JsonHash extends LinkedHashMap<String, Object> { public static JsonHash fromParser(JsonPullParser parser) throws IOException, JsonFormatException { State state = parser.getEventType(); if (state == State.VALUE_NULL) { return null; } else if (state != State.START_HASH) { throw new JsonFormatException("unexpected token. token=" + state, parser); } JsonHash jsonHash = new JsonHash(); while ((state = parser.lookAhead()) != State.END_HASH) { state = parser.getEventType(); if (state != State.KEY) { throw new JsonFormatException("unexpected token. token=" + state, parser); } String key = parser.getValueString(); state = parser.lookAhead(); jsonHash.put(key, getValue(parser), state); } parser.getEventType(); return jsonHash; }  static JsonHash fromString(String json); static JsonHash fromParser(JsonPullParser parser); void toJson(Writer writer); @Override void clear(); @Override Object clone(); @Deprecated State getState(String key); Type getType(String key); Boolean getBooleanOrNull(String key); String getStringOrNull(String key); Long getLongOrNull(String key); Double getDoubleOrNull(String key); JsonHash getJsonHashOrNull(String key); JsonArray getJsonArrayOrNull(String key); @Deprecated Object put(String key, Object value, State state); Object put(String key, Object value, Type type); Object put(String key, String value); Object put(String key, Boolean value); Object put(String key, Double value); Object put(String key, Float value); Object put(String key, Byte value); Object put(String key, Short value); Object put(String key, Integer value); Object put(String key, Long value); Object put(String key, JsonArray value); Object put(String key, JsonHash value); @Override Object put(String key, Object value); @Override void putAll(Map<? extends String, ? extends Object> map); @Override Object remove(Object obj); @Override boolean equals(Object obj); @Override String toString();  }