MCPcopy
hub / github.com/google/gson / parse

Method parse

gson/src/main/java/com/google/gson/internal/Streams.java:43–66  ·  view source on GitHub ↗

Takes a reader in any state and returns the next value as a JsonElement.

(JsonReader reader)

Source from the content-addressed store, hash-verified

41
42 /** Takes a reader in any state and returns the next value as a JsonElement. */
43 public static JsonElement parse(JsonReader reader) throws JsonParseException {
44 boolean isEmpty = true;
45 try {
46 JsonToken unused = reader.peek();
47 isEmpty = false;
48 return JsonElementTypeAdapter.ADAPTER.read(reader);
49 } catch (EOFException e) {
50 /*
51 * For compatibility with JSON 1.5 and earlier, we return a JsonNull for
52 * empty documents instead of throwing.
53 */
54 if (isEmpty) {
55 return JsonNull.INSTANCE;
56 }
57 // The stream ended prematurely so it is likely a syntax error.
58 throw new JsonSyntaxException(e);
59 } catch (MalformedJsonException e) {
60 throw new JsonSyntaxException(e);
61 } catch (IOException e) {
62 throw new JsonIOException(e);
63 } catch (NumberFormatException e) {
64 throw new JsonSyntaxException(e);
65 }
66 }
67
68 /** Writes the JSON element to the writer, recursively. */
69 public static void write(JsonElement element, JsonWriter writer) throws IOException {

Callers 6

createMethod · 0.95
readMethod · 0.95
nextMethod · 0.95
parseReaderMethod · 0.95
readMethod · 0.95

Calls 2

peekMethod · 0.45
readMethod · 0.45

Tested by 3

createMethod · 0.76
readMethod · 0.76