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(JsonElement pJson, String pMemberName) static BigIntegerconvertToBigInteger(JsonElement pJson, String pMemberName) static booleanconvertToBoolean(JsonElement pJson, String pMemberName) Gets the boolean value of the given JsonElement.static byteconvertToByte(JsonElement pJson, String pMemberName) static charconvertToCharacter(JsonElement pJson, String pMemberName) static doubleconvertToDouble(JsonElement pJson, String pMemberName) static floatconvertToFloat(JsonElement pJson, String pMemberName) Gets the float value of the given JsonElement.static intconvertToInt(JsonElement pJson, String pMemberName) Gets the integer value of the given JsonElement.convertToItem(JsonElement pJson, String pMemberName) static JsonArrayconvertToJsonArray(JsonElement pJson, String pMemberName) Gets the given JsonElement as a JsonArray.static JsonObjectconvertToJsonObject(JsonElement pJson, String pMemberName) Gets the given JsonElement as a JsonObject.static longconvertToLong(JsonElement pJson, String pMemberName) Gets a long from a JSON element and validates that the value is actually a number.static <T> TconvertToObject(JsonElement pJson, String pMemberName, JsonDeserializationContext pContext, Class<? extends T> pAdapter) static shortconvertToShort(JsonElement pJson, String pMemberName) static StringconvertToString(JsonElement pJson, String pMemberName) Gets the string value of the given JsonElement.static <T> Tstatic <T> Tstatic <T> Tstatic <T> Tstatic <T> Tstatic <T> Tstatic <T> TfromNullableJson(Gson pGson, Reader pReader, TypeToken<T> pType, boolean pLenient) static <T> TfromNullableJson(Gson pGson, Reader pReader, Class<T> pAdapter, boolean pLenient) static <T> TfromNullableJson(Gson pGson, String pJson, TypeToken<T> pType) static <T> TfromNullableJson(Gson pGson, String pJson, TypeToken<T> pType, boolean pLenient) static <T> TfromNullableJson(Gson pGson, String pJson, Class<T> pAdapter, boolean pLenient) static BigDecimalgetAsBigDecimal(JsonObject pJson, String pMemberName) static BigDecimalgetAsBigDecimal(JsonObject pJson, String pMemberName, BigDecimal pFallback) static BigIntegergetAsBigInteger(JsonObject pJson, String pMemberName) static BigIntegergetAsBigInteger(JsonObject pJson, String pMemberName, BigInteger pFallback) static booleangetAsBoolean(JsonObject pJson, String pMemberName) Gets the boolean value of the field on the JsonObject with the given name.static booleangetAsBoolean(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 bytegetAsByte(JsonObject pJson, String pMemberName) static bytegetAsByte(JsonObject pJson, String pMemberName, byte pFallback) static chargetAsCharacter(JsonObject pJson, String pMemberName) static chargetAsCharacter(JsonObject pJson, String pMemberName, char pFallback) static doublegetAsDouble(JsonObject pJson, String pMemberName) static doublegetAsDouble(JsonObject pJson, String pMemberName, double pFallback) static floatgetAsFloat(JsonObject pJson, String pMemberName) Gets the float value of the field on the JsonObject with the given name.static floatgetAsFloat(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 intgetAsInt(JsonObject pJson, String pMemberName) Gets the integer value of the field on the JsonObject with the given name.static intgetAsInt(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 JsonArraygetAsJsonArray(JsonObject pJson, String pMemberName) Gets the JsonArray field on the JsonObject with the given name.static JsonArraygetAsJsonArray(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 JsonObjectgetAsJsonObject(JsonObject pJson, String pMemberName) static JsonObjectgetAsJsonObject(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 longgetAsLong(JsonObject pJson, String pMemberName) Gets a long from a JSON element, throws an error if the member does not exist.static longgetAsLong(JsonObject pJson, String pMemberName, long pFallback) static <T> TgetAsObject(JsonObject pJson, String pMemberName, JsonDeserializationContext pContext, Class<? extends T> pAdapter) static <T> TgetAsObject(JsonObject pJson, String pMemberName, T pFallback, JsonDeserializationContext pContext, Class<? extends T> pAdapter) static shortgetAsShort(JsonObject pJson, String pMemberName) static shortgetAsShort(JsonObject pJson, String pMemberName, short pFallback) static StringgetAsString(JsonObject pJson, String pMemberName) Gets the string value of the field on the JsonObject with the given name.static StringgetAsString(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 JsonElementgetNonNull(JsonObject pJson, String pMemberName) static StringgetType(JsonElement pJson) Gets a human-readable description of the given JsonElement's type.static booleanisArrayNode(JsonObject pJson, String pMemberName) Does the given JsonObject contain an array field with the given name?static booleanisBooleanValue(JsonElement pJson) static booleanisBooleanValue(JsonObject pJson, String pMemberName) static booleanisNumberValue(JsonElement pJson) static booleanisNumberValue(JsonObject pJson, String pMemberName) static booleanisObjectNode(JsonObject pJson, String pMemberName) static booleanisStringValue(JsonElement pJson) Is the given JsonElement a string?static booleanisStringValue(JsonObject pJson, String pMemberName) Does the given JsonObject contain a string field with the given name?static booleanisValidNode(JsonObject pJson, String pMemberName) Does the given JsonObject contain a field with the given name?static booleanisValidPrimitive(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 JsonObjectstatic JsonObjectstatic JsonObjectstatic JsonObjectstatic JsonArrayparseArray(Reader pReader) static JsonArrayparseArray(String pString) private static Collection<Map.Entry<String, JsonElement>> sortByKeyIfNeeded(Collection<Map.Entry<String, JsonElement>> pEntries, Comparator<String> pSorter) static StringtoStableString(JsonElement pJson) static voidwriteValue(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)
-