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 element, String name) static BigIntegerconvertToBigInteger(JsonElement element, String name) static booleanconvertToBoolean(JsonElement element, String name) Gets the boolean value of the given JsonElement.static byteconvertToByte(JsonElement element, String name) static charconvertToCharacter(JsonElement element, String name) static doubleconvertToDouble(JsonElement element, String name) static floatconvertToFloat(JsonElement element, String name) Gets the float value of the given JsonElement.static intconvertToInt(JsonElement element, String name) Gets the integer value of the given JsonElement.convertToItem(JsonElement element, String name) static JsonArrayconvertToJsonArray(JsonElement element, String name) Gets the given JsonElement as a JsonArray.static JsonObjectconvertToJsonObject(JsonElement element, String name) Gets the given JsonElement as a JsonObject.static longconvertToLong(JsonElement element, String name) Gets a long from a JSON element and validates that the value is actually a number.static <T> TconvertToObject(@Nullable JsonElement element, String name, JsonDeserializationContext context, Class<? extends T> clazz) static shortconvertToShort(JsonElement element, String name) static StringconvertToString(JsonElement element, String name) Gets the string value of the given JsonElement.static booleanencodesLongerThan(JsonElement element, int limit) static <T> Tstatic <T> Tstatic <T> Tstatic <T> @Nullable TfromNullableJson(Gson gson, Reader reader, TypeToken<T> type) static <T> @Nullable TfromNullableJson(Gson gson, String string, TypeToken<T> type) static BigDecimalgetAsBigDecimal(JsonObject object, String name) static BigDecimalgetAsBigDecimal(JsonObject object, String name, BigDecimal def) static BigIntegergetAsBigInteger(JsonObject object, String name) static BigIntegergetAsBigInteger(JsonObject object, String name, BigInteger def) static booleangetAsBoolean(JsonObject object, String name) Gets the boolean value of the field on the JsonObject with the given name.static booleangetAsBoolean(JsonObject object, String name, boolean def) 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 object, String name) static bytegetAsByte(JsonObject object, String name, byte def) static chargetAsCharacter(JsonObject object, String name) static chargetAsCharacter(JsonObject object, String name, char def) static doublegetAsDouble(JsonObject object, String name) static doublegetAsDouble(JsonObject object, String name, double def) static floatgetAsFloat(JsonObject object, String name) Gets the float value of the field on the JsonObject with the given name.static floatgetAsFloat(JsonObject object, String name, float def) 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 object, String name) Gets the integer value of the field on the JsonObject with the given name.static intgetAsInt(JsonObject object, String name, int def) 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 object, String name) getAsItem(JsonObject object, String name, @Nullable Holder<Item> def) static JsonArraygetAsJsonArray(JsonObject object, String name) Gets the JsonArray field on the JsonObject with the given name.static @Nullable JsonArraygetAsJsonArray(JsonObject object, String name, @Nullable JsonArray def) Gets the JsonArray field on the JsonObject with the given name, or the given default value if the field is missing.static JsonObjectgetAsJsonObject(JsonObject object, String name) static @Nullable JsonObjectgetAsJsonObject(JsonObject object, String name, @Nullable JsonObject def) Gets the JsonObject field on the JsonObject with the given name, or the given default value if the field is missing.static longgetAsLong(JsonObject object, String name) Gets a long from a JSON element, throws an error if the member does not exist.static longgetAsLong(JsonObject object, String name, long def) static <T> @Nullable TgetAsObject(JsonObject object, String name, @Nullable T def, JsonDeserializationContext context, Class<? extends T> clazz) static <T> TgetAsObject(JsonObject object, String name, JsonDeserializationContext context, Class<? extends T> clazz) static shortgetAsShort(JsonObject object, String name) static shortgetAsShort(JsonObject object, String name, short def) static StringgetAsString(JsonObject object, String name) Gets the string value of the field on the JsonObject with the given name.static @Nullable StringgetAsString(JsonObject object, String name, @Nullable String def) 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 object, String name) static StringgetType(@Nullable JsonElement element) Gets a human-readable description of the given JsonElement's type.static booleanisArrayNode(JsonObject node, String name) Does the given JsonObject contain an array field with the given name?static booleanisBooleanValue(JsonElement node) static booleanisBooleanValue(JsonObject node, String name) static booleanisNumberValue(JsonElement node) static booleanisNumberValue(JsonObject node, String name) static booleanisObjectNode(JsonObject node, String name) static booleanisStringValue(JsonElement node) Is the given JsonElement a string?static booleanisStringValue(JsonObject node, String name) Does the given JsonObject contain a string field with the given name?static booleanisValidNode(@Nullable JsonObject node, String name) Does the given JsonObject contain a field with the given name?static booleanisValidPrimitive(JsonObject node, String name) 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 JsonArrayparseArray(Reader reader) static JsonArrayparseArray(String string) private static Collection<Map.Entry<String, JsonElement>> sortByKeyIfNeeded(Collection<Map.Entry<String, JsonElement>> elements, @Nullable Comparator<String> keyComparator) static StringtoStableString(JsonElement jsonElement) static voidwriteValue(JsonWriter out, @Nullable JsonElement value, @Nullable Comparator<String> keyComparator)
-
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
@Contract("_,_,!null->!null;_,_,null->_") public static @Nullable String getAsString(JsonObject object, String name, @Nullable String def) 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
@Contract("_,_,!null->!null;_,_,null->_") public static @Nullable JsonObject getAsJsonObject(JsonObject object, String name, @Nullable JsonObject def) 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
@Contract("_,_,!null->!null;_,_,null->_") public static @Nullable JsonArray getAsJsonArray(JsonObject object, String name, @Nullable JsonArray def) 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 element, String name, JsonDeserializationContext context, Class<? extends T> clazz) -
getAsObject
public static <T> T getAsObject(JsonObject object, String name, JsonDeserializationContext context, Class<? extends T> clazz) -
getAsObject
@Contract("_,_,!null,_,_->!null;_,_,null,_,_->_") public static <T> @Nullable T getAsObject(JsonObject object, String name, @Nullable T def, JsonDeserializationContext context, Class<? extends T> clazz) -
getType
Gets a human-readable description of the given JsonElement's type. For example: "a number (4)" -
fromJson
-
fromNullableJson
-
fromJson
-
fromNullableJson
-
fromJson
-
parse
-
parse
-
parseArray
-
parseArray
-
toStableString
-
writeValue
public static void writeValue(JsonWriter out, @Nullable JsonElement value, @Nullable Comparator<String> keyComparator) throws IOException - Throws:
IOException
-
sortByKeyIfNeeded
private static Collection<Map.Entry<String, JsonElement>> sortByKeyIfNeeded(Collection<Map.Entry<String, JsonElement>> elements, @Nullable Comparator<String> keyComparator) -
encodesLongerThan
-