Package net.minecraft.util
Class GsonHelper
java.lang.Object
net.minecraft.util.GsonHelper
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BigDecimalconvertToBigDecimal(com.google.gson.JsonElement json, String memberName) static BigIntegerconvertToBigInteger(com.google.gson.JsonElement json, String memberName) static booleanconvertToBoolean(com.google.gson.JsonElement json, String memberName) Gets the boolean value of the given JsonElement.static byteconvertToByte(com.google.gson.JsonElement json, String memberName) static charconvertToCharacter(com.google.gson.JsonElement json, String memberName) static doubleconvertToDouble(com.google.gson.JsonElement json, String memberName) static floatconvertToFloat(com.google.gson.JsonElement json, String memberName) Gets the float value of the given JsonElement.static intconvertToInt(com.google.gson.JsonElement json, String memberName) Gets the integer value of the given JsonElement.convertToItem(com.google.gson.JsonElement json, String memberName) static com.google.gson.JsonArrayconvertToJsonArray(com.google.gson.JsonElement json, String memberName) Gets the given JsonElement as a JsonArray.static com.google.gson.JsonObjectconvertToJsonObject(com.google.gson.JsonElement json, String memberName) Gets the given JsonElement as a JsonObject.static longconvertToLong(com.google.gson.JsonElement json, String memberName) Gets a long from a JSON element and validates that the value is actually a number.static <T> TconvertToObject(com.google.gson.JsonElement json, String memberName, com.google.gson.JsonDeserializationContext context, Class<? extends T> adapter) static shortconvertToShort(com.google.gson.JsonElement json, String memberName) static StringconvertToString(com.google.gson.JsonElement json, String memberName) Gets the string value of the given JsonElement.static <T> Tstatic <T> TfromJson(com.google.gson.Gson gson, Reader reader, com.google.gson.reflect.TypeToken<T> type, boolean lenient) static <T> Tstatic <T> Tstatic <T> Tstatic <T> Tstatic <T> TfromNullableJson(com.google.gson.Gson gson, Reader reader, com.google.gson.reflect.TypeToken<T> type, boolean lenient) static <T> TfromNullableJson(com.google.gson.Gson gson, Reader reader, Class<T> adapter, boolean lenient) static <T> TfromNullableJson(com.google.gson.Gson gson, String json, com.google.gson.reflect.TypeToken<T> type) static <T> TfromNullableJson(com.google.gson.Gson gson, String json, com.google.gson.reflect.TypeToken<T> type, boolean lenient) static <T> TfromNullableJson(com.google.gson.Gson gson, String json, Class<T> adapter, boolean lenient) static BigDecimalgetAsBigDecimal(com.google.gson.JsonObject json, String memberName) static BigDecimalgetAsBigDecimal(com.google.gson.JsonObject json, String memberName, BigDecimal fallback) static BigIntegergetAsBigInteger(com.google.gson.JsonObject json, String memberName) static BigIntegergetAsBigInteger(com.google.gson.JsonObject json, String memberName, BigInteger fallback) static booleangetAsBoolean(com.google.gson.JsonObject json, String memberName) Gets the boolean value of the field on the JsonObject with the given name.static booleangetAsBoolean(com.google.gson.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 bytestatic bytestatic chargetAsCharacter(com.google.gson.JsonObject json, String memberName) static chargetAsCharacter(com.google.gson.JsonObject json, String memberName, char fallback) static doublegetAsDouble(com.google.gson.JsonObject json, String memberName) static doublegetAsDouble(com.google.gson.JsonObject json, String memberName, double fallback) static floatgetAsFloat(com.google.gson.JsonObject json, String memberName) Gets the float value of the field on the JsonObject with the given name.static floatgetAsFloat(com.google.gson.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 intGets the integer value of the field on the JsonObject with the given name.static intGets the integer value of the field on the JsonObject with the given name, or the given default value if the field is missing.static com.google.gson.JsonArraygetAsJsonArray(com.google.gson.JsonObject json, String memberName) Gets the JsonArray field on the JsonObject with the given name.static com.google.gson.JsonArraygetAsJsonArray(com.google.gson.JsonObject json, String memberName, com.google.gson.JsonArray fallback) Gets the JsonArray field on the JsonObject with the given name, or the given default value if the field is missing.static com.google.gson.JsonObjectgetAsJsonObject(com.google.gson.JsonObject json, String memberName) static com.google.gson.JsonObjectgetAsJsonObject(com.google.gson.JsonObject json, String memberName, com.google.gson.JsonObject fallback) Gets the JsonObject field on the JsonObject with the given name, or the given default value if the field is missing.static longGets a long from a JSON element, throws an error if the member does not exist.static longstatic <T> TgetAsObject(com.google.gson.JsonObject json, String memberName, com.google.gson.JsonDeserializationContext context, Class<? extends T> adapter) static <T> TgetAsObject(com.google.gson.JsonObject json, String memberName, T fallback, com.google.gson.JsonDeserializationContext context, Class<? extends T> adapter) static shortgetAsShort(com.google.gson.JsonObject json, String memberName) static shortgetAsShort(com.google.gson.JsonObject json, String memberName, short fallback) static StringgetAsString(com.google.gson.JsonObject json, String memberName) Gets the string value of the field on the JsonObject with the given name.static StringgetAsString(com.google.gson.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 com.google.gson.JsonElementgetNonNull(com.google.gson.JsonObject json, String memberName) static StringgetType(com.google.gson.JsonElement json) Gets a human-readable description of the given JsonElement's type.static booleanisArrayNode(com.google.gson.JsonObject json, String memberName) Does the given JsonObject contain an array field with the given name?static booleanisBooleanValue(com.google.gson.JsonElement json) static booleanisBooleanValue(com.google.gson.JsonObject json, String memberName) static booleanisNumberValue(com.google.gson.JsonElement json) static booleanisNumberValue(com.google.gson.JsonObject json, String memberName) static booleanisObjectNode(com.google.gson.JsonObject json, String memberName) static booleanisStringValue(com.google.gson.JsonElement json) Is the given JsonElement a string?static booleanisStringValue(com.google.gson.JsonObject json, String memberName) Does the given JsonObject contain a string field with the given name?static booleanisValidNode(com.google.gson.JsonObject json, String memberName) Does the given JsonObject contain a field with the given name?static booleanisValidPrimitive(com.google.gson.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 com.google.gson.JsonObjectstatic com.google.gson.JsonObjectstatic com.google.gson.JsonObjectstatic com.google.gson.JsonObjectstatic com.google.gson.JsonArrayparseArray(Reader reader) static com.google.gson.JsonArrayparseArray(String string) private static Collection<Map.Entry<String, com.google.gson.JsonElement>> sortByKeyIfNeeded(Collection<Map.Entry<String, com.google.gson.JsonElement>> entries, Comparator<String> sorter) static StringtoStableString(com.google.gson.JsonElement json) static voidwriteValue(com.google.gson.stream.JsonWriter writer, com.google.gson.JsonElement jsonElement, Comparator<String> sorter)
-
Field Details
-
GSON
private static final com.google.gson.Gson GSON
-
-
Constructor Details
-
GsonHelper
public GsonHelper()
-
-
Method Details
-
isStringValue
Does the given JsonObject contain a string field with the given name? -
isStringValue
public static boolean isStringValue(com.google.gson.JsonElement json) Is the given JsonElement a string? -
isNumberValue
-
isNumberValue
public static boolean isNumberValue(com.google.gson.JsonElement json) -
isBooleanValue
-
isBooleanValue
public static boolean isBooleanValue(com.google.gson.JsonElement json) -
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
public static com.google.gson.JsonElement getNonNull(com.google.gson.JsonObject json, String memberName) -
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(com.google.gson.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
public static boolean getAsBoolean(com.google.gson.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. -
convertToDouble
-
getAsDouble
-
getAsDouble
public static double getAsDouble(com.google.gson.JsonObject json, String memberName, double fallback) -
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
public static char getAsCharacter(com.google.gson.JsonObject json, String memberName, char fallback) -
convertToBigDecimal
-
getAsBigDecimal
-
getAsBigDecimal
public static BigDecimal getAsBigDecimal(com.google.gson.JsonObject json, String memberName, BigDecimal fallback) -
convertToBigInteger
-
getAsBigInteger
-
getAsBigInteger
public static BigInteger getAsBigInteger(com.google.gson.JsonObject json, String memberName, BigInteger fallback) -
convertToShort
-
getAsShort
-
getAsShort
-
convertToJsonObject
public static com.google.gson.JsonObject convertToJsonObject(com.google.gson.JsonElement json, String memberName) 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
public static com.google.gson.JsonObject getAsJsonObject(com.google.gson.JsonObject json, String memberName) -
getAsJsonObject
@Nullable @Contract("_,_,!null->!null;_,_,null->_") public static com.google.gson.JsonObject getAsJsonObject(com.google.gson.JsonObject json, String memberName, @Nullable com.google.gson.JsonObject fallback) Gets the JsonObject field on the JsonObject with the given name, or the given default value if the field is missing. -
convertToJsonArray
public static com.google.gson.JsonArray convertToJsonArray(com.google.gson.JsonElement json, String memberName) 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
public static com.google.gson.JsonArray getAsJsonArray(com.google.gson.JsonObject json, String memberName) Gets the JsonArray field on the JsonObject with the given name. -
getAsJsonArray
@Nullable @Contract("_,_,!null->!null;_,_,null->_") public static com.google.gson.JsonArray getAsJsonArray(com.google.gson.JsonObject json, String memberName, @Nullable com.google.gson.JsonArray fallback) Gets the JsonArray field on the JsonObject with the given name, or the given default value if the field is missing. -
convertToObject
-
getAsObject
-
getAsObject
-
getType
Gets a human-readable description of the given JsonElement's type. For example: "a number (4)" -
fromNullableJson
-
fromJson
-
fromNullableJson
@Nullable public static <T> T fromNullableJson(com.google.gson.Gson gson, Reader reader, com.google.gson.reflect.TypeToken<T> type, boolean lenient) -
fromJson
public static <T> T fromJson(com.google.gson.Gson gson, Reader reader, com.google.gson.reflect.TypeToken<T> type, boolean lenient) -
fromNullableJson
@Nullable public static <T> T fromNullableJson(com.google.gson.Gson gson, String json, com.google.gson.reflect.TypeToken<T> type, boolean lenient) -
fromJson
-
fromNullableJson
-
fromJson
public static <T> T fromJson(com.google.gson.Gson gson, Reader reader, com.google.gson.reflect.TypeToken<T> type) -
fromNullableJson
@Nullable public static <T> T fromNullableJson(com.google.gson.Gson gson, String json, com.google.gson.reflect.TypeToken<T> type) -
fromJson
-
fromJson
-
parse
-
parse
-
parse
-
parse
-
parseArray
-
parseArray
-
toStableString
-
writeValue
public static void writeValue(com.google.gson.stream.JsonWriter writer, @Nullable com.google.gson.JsonElement jsonElement, @Nullable Comparator<String> sorter) throws IOException - Throws:
IOException
-
sortByKeyIfNeeded
private static Collection<Map.Entry<String,com.google.gson.JsonElement>> sortByKeyIfNeeded(Collection<Map.Entry<String, com.google.gson.JsonElement>> entries, @Nullable Comparator<String> sorter)
-