Package net.minecraft.util
Class GsonHelper
java.lang.Object
net.minecraft.util.GsonHelper
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BigDecimalconvertToBigDecimal(JsonElement json, String memberName) static BigIntegerconvertToBigInteger(JsonElement json, String memberName) static booleanconvertToBoolean(JsonElement json, String memberName) Gets the boolean value of the given JsonElement.static byteconvertToByte(JsonElement json, String memberName) static charconvertToCharacter(JsonElement json, String memberName) static doubleconvertToDouble(JsonElement json, String memberName) static floatconvertToFloat(JsonElement json, String memberName) Gets the float value of the given JsonElement.static intconvertToInt(JsonElement json, String memberName) Gets the integer value of the given JsonElement.convertToItem(JsonElement json, String memberName) static JsonArrayconvertToJsonArray(JsonElement json, String memberName) Gets the given JsonElement as a JsonArray.static JsonObjectconvertToJsonObject(JsonElement json, String memberName) Gets the given JsonElement as a JsonObject.static longconvertToLong(JsonElement json, String memberName) Gets a long from a JSON element and validates that the value is actually a number.static <T> TconvertToObject(JsonElement json, String memberName, JsonDeserializationContext context, Class<? extends T> adapter) static shortconvertToShort(JsonElement json, String memberName) static StringconvertToString(JsonElement json, String memberName) Gets the string value of the given JsonElement.static booleanencodesLongerThan(JsonElement element, int maxLength) static <T> Tstatic <T> Tstatic <T> Tstatic <T> Tstatic <T> Tstatic <T> Tstatic <T> TfromNullableJson(Gson gson, Reader reader, TypeToken<T> type, boolean lenient) static <T> TfromNullableJson(Gson gson, Reader reader, Class<T> adapter, boolean lenient) static <T> TfromNullableJson(Gson gson, String json, TypeToken<T> type) static <T> TfromNullableJson(Gson gson, String json, TypeToken<T> type, boolean lenient) static <T> TfromNullableJson(Gson gson, String json, Class<T> adapter, boolean lenient) static BigDecimalgetAsBigDecimal(JsonObject json, String memberName) static BigDecimalgetAsBigDecimal(JsonObject json, String memberName, BigDecimal fallback) static BigIntegergetAsBigInteger(JsonObject json, String memberName) static BigIntegergetAsBigInteger(JsonObject json, String memberName, BigInteger fallback) static booleangetAsBoolean(JsonObject json, String memberName) Gets the boolean value of the field on the JsonObject with the given name.static booleangetAsBoolean(JsonObject json, String memberName, boolean fallback) Gets the boolean value of the field on the JsonObject with the given name, or the given default value if the field is missing.static bytegetAsByte(JsonObject json, String memberName) static bytegetAsByte(JsonObject json, String memberName, byte fallback) static chargetAsCharacter(JsonObject json, String memberName) static chargetAsCharacter(JsonObject json, String memberName, char fallback) static doublegetAsDouble(JsonObject json, String memberName) static doublegetAsDouble(JsonObject json, String memberName, double fallback) static floatgetAsFloat(JsonObject json, String memberName) Gets the float value of the field on the JsonObject with the given name.static floatgetAsFloat(JsonObject json, String memberName, float fallback) Gets the float value of the field on the JsonObject with the given name, or the given default value if the field is missing.static intgetAsInt(JsonObject json, String memberName) Gets the integer value of the field on the JsonObject with the given name.static intgetAsInt(JsonObject json, String memberName, int fallback) Gets the integer value of the field on the JsonObject with the given name, or the given default value if the field is missing.getAsItem(JsonObject json, String memberName) getAsItem(JsonObject json, String memberName, Holder<Item> fallback) static JsonArraygetAsJsonArray(JsonObject json, String memberName) Gets the JsonArray field on the JsonObject with the given name.static JsonArraygetAsJsonArray(JsonObject json, String memberName, JsonArray fallback) Gets the JsonArray field on the JsonObject with the given name, or the given default value if the field is missing.static JsonObjectgetAsJsonObject(JsonObject json, String memberName) static JsonObjectgetAsJsonObject(JsonObject json, String memberName, JsonObject fallback) Gets the JsonObject field on the JsonObject with the given name, or the given default value if the field is missing.static longgetAsLong(JsonObject json, String memberName) Gets a long from a JSON element, throws an error if the member does not exist.static longgetAsLong(JsonObject json, String memberName, long fallback) static <T> TgetAsObject(JsonObject json, String memberName, JsonDeserializationContext context, Class<? extends T> adapter) static <T> TgetAsObject(JsonObject json, String memberName, T fallback, JsonDeserializationContext context, Class<? extends T> adapter) static shortgetAsShort(JsonObject json, String memberName) static shortgetAsShort(JsonObject json, String memberName, short fallback) static StringgetAsString(JsonObject json, String memberName) Gets the string value of the field on the JsonObject with the given name.static StringgetAsString(JsonObject json, String memberName, String fallback) Gets the string value of the field on the JsonObject with the given name, or the given default value if the field is missing.static JsonElementgetNonNull(JsonObject json, String memberName) static StringgetType(JsonElement json) Gets a human-readable description of the given JsonElement's type.static booleanisArrayNode(JsonObject json, String memberName) Does the given JsonObject contain an array field with the given name?static booleanisBooleanValue(JsonElement json) static booleanisBooleanValue(JsonObject json, String memberName) static booleanisNumberValue(JsonElement json) static booleanisNumberValue(JsonObject json, String memberName) static booleanisObjectNode(JsonObject json, String memberName) static booleanisStringValue(JsonElement json) Is the given JsonElement a string?static booleanisStringValue(JsonObject json, String memberName) Does the given JsonObject contain a string field with the given name?static booleanisValidNode(JsonObject json, String memberName) Does the given JsonObject contain a field with the given name?static booleanisValidPrimitive(JsonObject json, String memberName) Does the given JsonObject contain a field with the given name whose type is primitive (String, Java primitive, or Java primitive wrapper)?static JsonObjectstatic JsonObjectstatic JsonObjectstatic JsonObjectstatic JsonArrayparseArray(Reader reader) static JsonArrayparseArray(String string) private static Collection<Map.Entry<String, JsonElement>> sortByKeyIfNeeded(Collection<Map.Entry<String, JsonElement>> entries, Comparator<String> sorter) static StringtoStableString(JsonElement json) static voidwriteValue(JsonWriter writer, JsonElement jsonElement, Comparator<String> sorter)
-
Field Details
-
GSON
-
-
Constructor Details
-
GsonHelper
public GsonHelper()
-
-
Method Details
-
isStringValue
Does the given JsonObject contain a string field with the given name? -
isStringValue
Is the given JsonElement a string? -
isNumberValue
-
isNumberValue
-
isBooleanValue
-
isBooleanValue
-
isArrayNode
Does the given JsonObject contain an array field with the given name? -
isObjectNode
-
isValidPrimitive
Does the given JsonObject contain a field with the given name whose type is primitive (String, Java primitive, or Java primitive wrapper)? -
isValidNode
Does the given JsonObject contain a field with the given name? -
getNonNull
-
convertToString
Gets the string value of the given JsonElement. Expects the second parameter to be the name of the element's field if an error message needs to be thrown. -
getAsString
Gets the string value of the field on the JsonObject with the given name. -
getAsString
@Nullable @Contract("_,_,!null->!null;_,_,null->_") public static String getAsString(JsonObject json, String memberName, @Nullable String fallback) Gets the string value of the field on the JsonObject with the given name, or the given default value if the field is missing. -
convertToItem
-
getAsItem
-
getAsItem
-
convertToBoolean
Gets the boolean value of the given JsonElement. Expects the second parameter to be the name of the element's field if an error message needs to be thrown. -
getAsBoolean
Gets the boolean value of the field on the JsonObject with the given name. -
getAsBoolean
Gets the boolean value of the field on the JsonObject with the given name, or the given default value if the field is missing. -
convertToDouble
-
getAsDouble
-
getAsDouble
-
convertToFloat
Gets the float value of the given JsonElement. Expects the second parameter to be the name of the element's field if an error message needs to be thrown. -
getAsFloat
Gets the float value of the field on the JsonObject with the given name. -
getAsFloat
Gets the float value of the field on the JsonObject with the given name, or the given default value if the field is missing. -
convertToLong
Gets a long from a JSON element and validates that the value is actually a number. -
getAsLong
Gets a long from a JSON element, throws an error if the member does not exist. -
getAsLong
-
convertToInt
Gets the integer value of the given JsonElement. Expects the second parameter to be the name of the element's field if an error message needs to be thrown. -
getAsInt
Gets the integer value of the field on the JsonObject with the given name. -
getAsInt
Gets the integer value of the field on the JsonObject with the given name, or the given default value if the field is missing. -
convertToByte
-
getAsByte
-
getAsByte
-
convertToCharacter
-
getAsCharacter
-
getAsCharacter
-
convertToBigDecimal
-
getAsBigDecimal
-
getAsBigDecimal
-
convertToBigInteger
-
getAsBigInteger
-
getAsBigInteger
-
convertToShort
-
getAsShort
-
getAsShort
-
convertToJsonObject
Gets the given JsonElement as a JsonObject. Expects the second parameter to be the name of the element's field if an error message needs to be thrown. -
getAsJsonObject
-
getAsJsonObject
@Nullable @Contract("_,_,!null->!null;_,_,null->_") public static JsonObject getAsJsonObject(JsonObject json, String memberName, @Nullable JsonObject fallback) Gets the JsonObject field on the JsonObject with the given name, or the given default value if the field is missing. -
convertToJsonArray
Gets the given JsonElement as a JsonArray. Expects the second parameter to be the name of the element's field if an error message needs to be thrown. -
getAsJsonArray
Gets the JsonArray field on the JsonObject with the given name. -
getAsJsonArray
@Nullable @Contract("_,_,!null->!null;_,_,null->_") public static JsonArray getAsJsonArray(JsonObject json, String memberName, @Nullable JsonArray fallback) Gets the JsonArray field on the JsonObject with the given name, or the given default value if the field is missing. -
convertToObject
public static <T> T convertToObject(@Nullable JsonElement json, String memberName, JsonDeserializationContext context, Class<? extends T> adapter) -
getAsObject
public static <T> T getAsObject(JsonObject json, String memberName, JsonDeserializationContext context, Class<? extends T> adapter) -
getAsObject
@Nullable @Contract("_,_,!null,_,_->!null;_,_,null,_,_->_") public static <T> T getAsObject(JsonObject json, String memberName, @Nullable T fallback, JsonDeserializationContext context, Class<? extends T> adapter) -
getType
Gets a human-readable description of the given JsonElement's type. For example: "a number (4)" -
fromNullableJson
-
fromJson
-
fromNullableJson
-
fromJson
-
fromNullableJson
-
fromJson
-
fromNullableJson
-
fromJson
-
fromNullableJson
-
fromJson
-
fromJson
-
parse
-
parse
-
parse
-
parse
-
parseArray
-
parseArray
-
toStableString
-
writeValue
public static void writeValue(JsonWriter writer, @Nullable JsonElement jsonElement, @Nullable Comparator<String> sorter) throws IOException - Throws:
IOException
-
sortByKeyIfNeeded
private static Collection<Map.Entry<String,JsonElement>> sortByKeyIfNeeded(Collection<Map.Entry<String, JsonElement>> entries, @Nullable Comparator<String> sorter) -
encodesLongerThan
-