Package net.minecraft.util
Class GsonHelper
java.lang.Object
net.minecraft.util.GsonHelper
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BigDecimal
convertToBigDecimal
(JsonElement pJson, String pMemberName) static BigInteger
convertToBigInteger
(JsonElement pJson, String pMemberName) static boolean
convertToBoolean
(JsonElement pJson, String pMemberName) Gets the boolean value of the given JsonElement.static byte
convertToByte
(JsonElement pJson, String pMemberName) static char
convertToCharacter
(JsonElement pJson, String pMemberName) static double
convertToDouble
(JsonElement pJson, String pMemberName) static float
convertToFloat
(JsonElement pJson, String pMemberName) Gets the float value of the given JsonElement.static int
convertToInt
(JsonElement pJson, String pMemberName) Gets the integer value of the given JsonElement.convertToItem
(JsonElement pJson, String pMemberName) static JsonArray
convertToJsonArray
(JsonElement pJson, String pMemberName) Gets the given JsonElement as a JsonArray.static JsonObject
convertToJsonObject
(JsonElement pJson, String pMemberName) Gets the given JsonElement as a JsonObject.static long
convertToLong
(JsonElement pJson, String pMemberName) Gets a long from a JSON element and validates that the value is actually a number.static <T> T
convertToObject
(JsonElement pJson, String pMemberName, JsonDeserializationContext pContext, Class<? extends T> pAdapter) static short
convertToShort
(JsonElement pJson, String pMemberName) static String
convertToString
(JsonElement pJson, String pMemberName) Gets the string value of the given JsonElement.static <T> T
static <T> T
static <T> T
static <T> T
static <T> T
static <T> T
static <T> T
fromNullableJson
(Gson pGson, Reader pReader, TypeToken<T> pType, boolean pLenient) static <T> T
fromNullableJson
(Gson pGson, Reader pReader, Class<T> pAdapter, boolean pLenient) static <T> T
fromNullableJson
(Gson pGson, String pJson, TypeToken<T> pType) static <T> T
fromNullableJson
(Gson pGson, String pJson, TypeToken<T> pType, boolean pLenient) static <T> T
fromNullableJson
(Gson pGson, String pJson, Class<T> pAdapter, boolean pLenient) static BigDecimal
getAsBigDecimal
(JsonObject pJson, String pMemberName) static BigDecimal
getAsBigDecimal
(JsonObject pJson, String pMemberName, BigDecimal pFallback) static BigInteger
getAsBigInteger
(JsonObject pJson, String pMemberName) static BigInteger
getAsBigInteger
(JsonObject pJson, String pMemberName, BigInteger pFallback) static boolean
getAsBoolean
(JsonObject pJson, String pMemberName) Gets the boolean value of the field on the JsonObject with the given name.static boolean
getAsBoolean
(JsonObject pJson, String pMemberName, boolean pFallback) 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 byte
getAsByte
(JsonObject pJson, String pMemberName) static byte
getAsByte
(JsonObject pJson, String pMemberName, byte pFallback) static char
getAsCharacter
(JsonObject pJson, String pMemberName) static char
getAsCharacter
(JsonObject pJson, String pMemberName, char pFallback) static double
getAsDouble
(JsonObject pJson, String pMemberName) static double
getAsDouble
(JsonObject pJson, String pMemberName, double pFallback) static float
getAsFloat
(JsonObject pJson, String pMemberName) Gets the float value of the field on the JsonObject with the given name.static float
getAsFloat
(JsonObject pJson, String pMemberName, float pFallback) 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 int
getAsInt
(JsonObject pJson, String pMemberName) Gets the integer value of the field on the JsonObject with the given name.static int
getAsInt
(JsonObject pJson, String pMemberName, int pFallback) 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 pJson, String pMemberName) getAsItem
(JsonObject pJson, String pMemberName, Holder<Item> pFallback) static JsonArray
getAsJsonArray
(JsonObject pJson, String pMemberName) Gets the JsonArray field on the JsonObject with the given name.static JsonArray
getAsJsonArray
(JsonObject pJson, String pMemberName, JsonArray pFallback) Gets the JsonArray field on the JsonObject with the given name, or the given default value if the field is missing.static JsonObject
getAsJsonObject
(JsonObject pJson, String pMemberName) static JsonObject
getAsJsonObject
(JsonObject pJson, String pMemberName, JsonObject pFallback) Gets the JsonObject field on the JsonObject with the given name, or the given default value if the field is missing.static long
getAsLong
(JsonObject pJson, String pMemberName) Gets a long from a JSON element, throws an error if the member does not exist.static long
getAsLong
(JsonObject pJson, String pMemberName, long pFallback) static <T> T
getAsObject
(JsonObject pJson, String pMemberName, JsonDeserializationContext pContext, Class<? extends T> pAdapter) static <T> T
getAsObject
(JsonObject pJson, String pMemberName, T pFallback, JsonDeserializationContext pContext, Class<? extends T> pAdapter) static short
getAsShort
(JsonObject pJson, String pMemberName) static short
getAsShort
(JsonObject pJson, String pMemberName, short pFallback) static String
getAsString
(JsonObject pJson, String pMemberName) Gets the string value of the field on the JsonObject with the given name.static String
getAsString
(JsonObject pJson, String pMemberName, String pFallback) 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 JsonElement
getNonNull
(JsonObject pJson, String pMemberName) static String
getType
(JsonElement pJson) Gets a human-readable description of the given JsonElement's type.static boolean
isArrayNode
(JsonObject pJson, String pMemberName) Does the given JsonObject contain an array field with the given name?static boolean
isBooleanValue
(JsonElement pJson) static boolean
isBooleanValue
(JsonObject pJson, String pMemberName) static boolean
isNumberValue
(JsonElement pJson) static boolean
isNumberValue
(JsonObject pJson, String pMemberName) static boolean
isObjectNode
(JsonObject pJson, String pMemberName) static boolean
isStringValue
(JsonElement pJson) Is the given JsonElement a string?static boolean
isStringValue
(JsonObject pJson, String pMemberName) Does the given JsonObject contain a string field with the given name?static boolean
isValidNode
(JsonObject pJson, String pMemberName) Does the given JsonObject contain a field with the given name?static boolean
isValidPrimitive
(JsonObject pJson, String pMemberName) Does the given JsonObject contain a field with the given name whose type is primitive (String, Java primitive, or Java primitive wrapper)?static JsonObject
static JsonObject
static JsonObject
static JsonObject
static JsonArray
parseArray
(Reader pReader) static JsonArray
parseArray
(String pString) private static Collection
<Map.Entry<String, JsonElement>> sortByKeyIfNeeded
(Collection<Map.Entry<String, JsonElement>> pEntries, Comparator<String> pSorter) static String
toStableString
(JsonElement pJson) static void
writeValue
(JsonWriter pWriter, JsonElement pJsonElement, Comparator<String> pSorter)
-
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 pJson, String pMemberName, @Nullable String pFallback) 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
public static BigDecimal getAsBigDecimal(JsonObject pJson, String pMemberName, BigDecimal pFallback) -
convertToBigInteger
-
getAsBigInteger
-
getAsBigInteger
public static BigInteger getAsBigInteger(JsonObject pJson, String pMemberName, BigInteger pFallback) -
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 pJson, String pMemberName, @Nullable JsonObject pFallback) 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 pJson, String pMemberName, @Nullable JsonArray pFallback) 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 pJson, String pMemberName, JsonDeserializationContext pContext, Class<? extends T> pAdapter) -
getAsObject
public static <T> T getAsObject(JsonObject pJson, String pMemberName, JsonDeserializationContext pContext, Class<? extends T> pAdapter) -
getAsObject
@Nullable @Contract("_,_,!null,_,_->!null;_,_,null,_,_->_") public static <T> T getAsObject(JsonObject pJson, String pMemberName, @Nullable T pFallback, JsonDeserializationContext pContext, Class<? extends T> pAdapter) -
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 pWriter, @Nullable JsonElement pJsonElement, @Nullable Comparator<String> pSorter) throws IOException - Throws:
IOException
-
sortByKeyIfNeeded
private static Collection<Map.Entry<String,JsonElement>> sortByKeyIfNeeded(Collection<Map.Entry<String, JsonElement>> pEntries, @Nullable Comparator<String> pSorter)
-