StrictJsonParser .java

net.minecraft.util.StrictJsonParser (class): members: parse. strings: "Did not consume the entire document.". imports: MalformedJsonException, JsonToken.

net.minecraft.utilclass37 linescommon1.2 KB

API Surface (2)

JsonElement parse(final Reader reader)
JsonElement parse(final String json)

String literals (1)

"Did not consume the entire document."

Full Source

StrictJsonParser.java37 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.util;
2
3
import com.google.gson.JsonElement;
4
import com.google.gson.JsonIOException;
5
import com.google.gson.JsonParser;
6
import com.google.gson.JsonSyntaxException;
7
import com.google.gson.Strictness;
8
import com.google.gson.stream.JsonReader;
9
import com.google.gson.stream.JsonToken;
10
import com.google.gson.stream.MalformedJsonException;
11
import java.io.IOException;
12
import java.io.Reader;
13
import java.io.StringReader;
14
15
public class StrictJsonParser {
16
	public static JsonElement parse(final Reader reader) throws JsonIOException, JsonSyntaxException {
17
		try {
18
			JsonReader jsonReader = new JsonReader(reader);
19
			jsonReader.setStrictness(Strictness.STRICT);
20
			JsonElement element = JsonParser.parseReader(jsonReader);
21
			if (!element.isJsonNull() && jsonReader.peek() != JsonToken.END_DOCUMENT) {
22
				throw new JsonSyntaxException("Did not consume the entire document.");
23
			} else {
24
				return element;
25
			}
26
		} catch (MalformedJsonException | NumberFormatException e) {
27
			throw new JsonSyntaxException(e);
28
		} catch (IOException e) {
29
			throw new JsonIOException(e);
30
		}
31
	}
32
33
	public static JsonElement parse(final String json) throws JsonSyntaxException {
34
		return parse(new StringReader(json));
35
	}
36
}
37

Decompiled Minecraft 26.3 source of StrictJsonParser (net/minecraft/util/StrictJsonParser.java) with Mojang official mappings, stored verbatim on the site.