Takes a reader in any state and returns the next value as a JsonElement.
(JsonReader reader)
| 33 | * Takes a reader in any state and returns the next value as a JsonElement. |
| 34 | */ |
| 35 | static JsonElement parse(JsonReader reader) throws JsonParseException { |
| 36 | boolean isEmpty = true; |
| 37 | try { |
| 38 | reader.peek(); |
| 39 | isEmpty = false; |
| 40 | return parseRecursive(reader); |
| 41 | } catch (EOFException e) { |
| 42 | /* |
| 43 | * For compatibility with JSON 1.5 and earlier, we return a JsonNull for |
| 44 | * empty documents instead of throwing. |
| 45 | */ |
| 46 | if (isEmpty) { |
| 47 | return JsonNull.createJsonNull(); |
| 48 | } |
| 49 | throw new JsonIOException(e); |
| 50 | } catch (MalformedJsonException e) { |
| 51 | throw new JsonSyntaxException(e); |
| 52 | } catch (IOException e) { |
| 53 | throw new JsonIOException(e); |
| 54 | } catch (NumberFormatException e) { |
| 55 | throw new JsonSyntaxException(e); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | private static JsonElement parseRecursive(JsonReader reader) throws IOException { |
| 60 | switch (reader.peek()) { |