2025-11-24 22:52:51 +03:00

52 lines
1.7 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.google.gson.JsonElement
* com.google.gson.JsonIOException
* com.google.gson.JsonParser
* com.google.gson.JsonSyntaxException
* com.google.gson.Strictness
* com.google.gson.stream.JsonReader
* com.google.gson.stream.JsonToken
* com.google.gson.stream.MalformedJsonException
*/
package net.minecraft.util;
import com.google.gson.JsonElement;
import com.google.gson.JsonIOException;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.google.gson.Strictness;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.MalformedJsonException;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
public class StrictJsonParser {
public static JsonElement parse(Reader reader) throws JsonIOException, JsonSyntaxException {
try {
JsonReader jsonReader = new JsonReader(reader);
jsonReader.setStrictness(Strictness.STRICT);
JsonElement element = JsonParser.parseReader((JsonReader)jsonReader);
if (!element.isJsonNull() && jsonReader.peek() != JsonToken.END_DOCUMENT) {
throw new JsonSyntaxException("Did not consume the entire document.");
}
return element;
}
catch (MalformedJsonException | NumberFormatException e) {
throw new JsonSyntaxException(e);
}
catch (IOException e) {
throw new JsonIOException((Throwable)e);
}
}
public static JsonElement parse(String json) throws JsonSyntaxException {
return StrictJsonParser.parse(new StringReader(json));
}
}