Class GsonHelper

java.lang.Object
net.minecraft.util.GsonHelper

public class GsonHelper extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final com.google.gson.Gson
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static BigDecimal
    convertToBigDecimal(com.google.gson.JsonElement pJson, String pMemberName)
     
    static BigInteger
    convertToBigInteger(com.google.gson.JsonElement pJson, String pMemberName)
     
    static boolean
    convertToBoolean(com.google.gson.JsonElement pJson, String pMemberName)
    Gets the boolean value of the given JsonElement.
    static byte
    convertToByte(com.google.gson.JsonElement pJson, String pMemberName)
     
    static char
    convertToCharacter(com.google.gson.JsonElement pJson, String pMemberName)
     
    static double
    convertToDouble(com.google.gson.JsonElement pJson, String pMemberName)
     
    static float
    convertToFloat(com.google.gson.JsonElement pJson, String pMemberName)
    Gets the float value of the given JsonElement.
    static int
    convertToInt(com.google.gson.JsonElement pJson, String pMemberName)
    Gets the integer value of the given JsonElement.
    static Holder<Item>
    convertToItem(com.google.gson.JsonElement pJson, String pMemberName)
     
    static com.google.gson.JsonArray
    convertToJsonArray(com.google.gson.JsonElement pJson, String pMemberName)
    Gets the given JsonElement as a JsonArray.
    static com.google.gson.JsonObject
    convertToJsonObject(com.google.gson.JsonElement pJson, String pMemberName)
    Gets the given JsonElement as a JsonObject.
    static long
    convertToLong(com.google.gson.JsonElement pJson, String pMemberName)
    Gets a long from a JSON element and validates that the value is actually a number.
    static <T> T
    convertToObject(com.google.gson.JsonElement pJson, String pMemberName, com.google.gson.JsonDeserializationContext pContext, Class<? extends T> pAdapter)
     
    static short
    convertToShort(com.google.gson.JsonElement pJson, String pMemberName)
     
    static String
    convertToString(com.google.gson.JsonElement pJson, String pMemberName)
    Gets the string value of the given JsonElement.
    static <T> T
    fromJson(com.google.gson.Gson pGson, Reader pReader, com.google.gson.reflect.TypeToken<T> pType)
     
    static <T> T
    fromJson(com.google.gson.Gson pGson, Reader pReader, com.google.gson.reflect.TypeToken<T> pType, boolean pLenient)
     
    static <T> T
    fromJson(com.google.gson.Gson pGson, Reader pReader, Class<T> pJsonClass)
     
    static <T> T
    fromJson(com.google.gson.Gson pGson, Reader pReader, Class<T> pAdapter, boolean pLenient)
     
    static <T> T
    fromJson(com.google.gson.Gson pGson, String pJson, Class<T> pAdapter)
     
    static <T> T
    fromJson(com.google.gson.Gson pGson, String pJson, Class<T> pAdapter, boolean pLenient)
     
    static <T> T
    fromNullableJson(com.google.gson.Gson pGson, Reader pReader, com.google.gson.reflect.TypeToken<T> pType, boolean pLenient)
     
    static <T> T
    fromNullableJson(com.google.gson.Gson pGson, Reader pReader, Class<T> pAdapter, boolean pLenient)
     
    static <T> T
    fromNullableJson(com.google.gson.Gson pGson, String pJson, com.google.gson.reflect.TypeToken<T> pType)
     
    static <T> T
    fromNullableJson(com.google.gson.Gson pGson, String pJson, com.google.gson.reflect.TypeToken<T> pType, boolean pLenient)
     
    static <T> T
    fromNullableJson(com.google.gson.Gson pGson, String pJson, Class<T> pAdapter, boolean pLenient)
     
    static BigDecimal
    getAsBigDecimal(com.google.gson.JsonObject pJson, String pMemberName)
     
    static BigDecimal
    getAsBigDecimal(com.google.gson.JsonObject pJson, String pMemberName, BigDecimal pFallback)
     
    static BigInteger
    getAsBigInteger(com.google.gson.JsonObject pJson, String pMemberName)
     
    static BigInteger
    getAsBigInteger(com.google.gson.JsonObject pJson, String pMemberName, BigInteger pFallback)
     
    static boolean
    getAsBoolean(com.google.gson.JsonObject pJson, String pMemberName)
    Gets the boolean value of the field on the JsonObject with the given name.
    static boolean
    getAsBoolean(com.google.gson.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(com.google.gson.JsonObject pJson, String pMemberName)
     
    static byte
    getAsByte(com.google.gson.JsonObject pJson, String pMemberName, byte pFallback)
     
    static char
    getAsCharacter(com.google.gson.JsonObject pJson, String pMemberName)
     
    static char
    getAsCharacter(com.google.gson.JsonObject pJson, String pMemberName, char pFallback)
     
    static double
    getAsDouble(com.google.gson.JsonObject pJson, String pMemberName)
     
    static double
    getAsDouble(com.google.gson.JsonObject pJson, String pMemberName, double pFallback)
     
    static float
    getAsFloat(com.google.gson.JsonObject pJson, String pMemberName)
    Gets the float value of the field on the JsonObject with the given name.
    static float
    getAsFloat(com.google.gson.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(com.google.gson.JsonObject pJson, String pMemberName)
    Gets the integer value of the field on the JsonObject with the given name.
    static int
    getAsInt(com.google.gson.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.
    static Holder<Item>
    getAsItem(com.google.gson.JsonObject pJson, String pMemberName)
     
    static Holder<Item>
    getAsItem(com.google.gson.JsonObject pJson, String pMemberName, Holder<Item> pFallback)
     
    static com.google.gson.JsonArray
    getAsJsonArray(com.google.gson.JsonObject pJson, String pMemberName)
    Gets the JsonArray field on the JsonObject with the given name.
    static com.google.gson.JsonArray
    getAsJsonArray(com.google.gson.JsonObject pJson, String pMemberName, com.google.gson.JsonArray pFallback)
    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.JsonObject
    getAsJsonObject(com.google.gson.JsonObject pJson, String pMemberName)
     
    static com.google.gson.JsonObject
    getAsJsonObject(com.google.gson.JsonObject pJson, String pMemberName, com.google.gson.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(com.google.gson.JsonObject pJson, String pMemberName)
    Gets a long from a JSON element, throws an error if the member does not exist.
    static long
    getAsLong(com.google.gson.JsonObject pJson, String pMemberName, long pFallback)
     
    static <T> T
    getAsObject(com.google.gson.JsonObject pJson, String pMemberName, com.google.gson.JsonDeserializationContext pContext, Class<? extends T> pAdapter)
     
    static <T> T
    getAsObject(com.google.gson.JsonObject pJson, String pMemberName, T pFallback, com.google.gson.JsonDeserializationContext pContext, Class<? extends T> pAdapter)
     
    static short
    getAsShort(com.google.gson.JsonObject pJson, String pMemberName)
     
    static short
    getAsShort(com.google.gson.JsonObject pJson, String pMemberName, short pFallback)
     
    static String
    getAsString(com.google.gson.JsonObject pJson, String pMemberName)
    Gets the string value of the field on the JsonObject with the given name.
    static String
    getAsString(com.google.gson.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 com.google.gson.JsonElement
    getNonNull(com.google.gson.JsonObject pJson, String pMemberName)
     
    static String
    getType(com.google.gson.JsonElement pJson)
    Gets a human-readable description of the given JsonElement's type.
    static boolean
    isArrayNode(com.google.gson.JsonObject pJson, String pMemberName)
    Does the given JsonObject contain an array field with the given name?
    static boolean
    isBooleanValue(com.google.gson.JsonElement pJson)
     
    static boolean
    isBooleanValue(com.google.gson.JsonObject pJson, String pMemberName)
     
    static boolean
    isNumberValue(com.google.gson.JsonElement pJson)
     
    static boolean
    isNumberValue(com.google.gson.JsonObject pJson, String pMemberName)
     
    static boolean
    isObjectNode(com.google.gson.JsonObject pJson, String pMemberName)
     
    static boolean
    isStringValue(com.google.gson.JsonElement pJson)
    Is the given JsonElement a string?
    static boolean
    isStringValue(com.google.gson.JsonObject pJson, String pMemberName)
    Does the given JsonObject contain a string field with the given name?
    static boolean
    isValidNode(com.google.gson.JsonObject pJson, String pMemberName)
    Does the given JsonObject contain a field with the given name?
    static boolean
    isValidPrimitive(com.google.gson.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 com.google.gson.JsonObject
    parse(Reader pReader)
     
    static com.google.gson.JsonObject
    parse(Reader pReader, boolean pLenient)
     
    static com.google.gson.JsonObject
    parse(String pJson)
     
    static com.google.gson.JsonObject
    parse(String pJson, boolean pLenient)
     
    static com.google.gson.JsonArray
    parseArray(Reader pReader)
     
    static com.google.gson.JsonArray
    parseArray(String pString)
     
    private static Collection<Map.Entry<String,com.google.gson.JsonElement>>
    sortByKeyIfNeeded(Collection<Map.Entry<String,com.google.gson.JsonElement>> pEntries, Comparator<String> pSorter)
     
    static String
    toStableString(com.google.gson.JsonElement pJson)
     
    static void
    writeValue(com.google.gson.stream.JsonWriter pWriter, com.google.gson.JsonElement pJsonElement, Comparator<String> pSorter)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • GSON

      private static final com.google.gson.Gson GSON
  • Constructor Details

    • GsonHelper

      public GsonHelper()
  • Method Details

    • isStringValue

      public static boolean isStringValue(com.google.gson.JsonObject pJson, String pMemberName)
      Does the given JsonObject contain a string field with the given name?
    • isStringValue

      public static boolean isStringValue(com.google.gson.JsonElement pJson)
      Is the given JsonElement a string?
    • isNumberValue

      public static boolean isNumberValue(com.google.gson.JsonObject pJson, String pMemberName)
    • isNumberValue

      public static boolean isNumberValue(com.google.gson.JsonElement pJson)
    • isBooleanValue

      public static boolean isBooleanValue(com.google.gson.JsonObject pJson, String pMemberName)
    • isBooleanValue

      public static boolean isBooleanValue(com.google.gson.JsonElement pJson)
    • isArrayNode

      public static boolean isArrayNode(com.google.gson.JsonObject pJson, String pMemberName)
      Does the given JsonObject contain an array field with the given name?
    • isObjectNode

      public static boolean isObjectNode(com.google.gson.JsonObject pJson, String pMemberName)
    • isValidPrimitive

      public static boolean isValidPrimitive(com.google.gson.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)?
    • isValidNode

      public static boolean isValidNode(@Nullable com.google.gson.JsonObject pJson, String pMemberName)
      Does the given JsonObject contain a field with the given name?
    • getNonNull

      public static com.google.gson.JsonElement getNonNull(com.google.gson.JsonObject pJson, String pMemberName)
    • convertToString

      public static String convertToString(com.google.gson.JsonElement pJson, String pMemberName)
      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

      public static String getAsString(com.google.gson.JsonObject pJson, String pMemberName)
      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 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

      public static Holder<Item> convertToItem(com.google.gson.JsonElement pJson, String pMemberName)
    • getAsItem

      public static Holder<Item> getAsItem(com.google.gson.JsonObject pJson, String pMemberName)
    • getAsItem

      @Nullable @Contract("_,_,!null->!null;_,_,null->_") public static Holder<Item> getAsItem(com.google.gson.JsonObject pJson, String pMemberName, @Nullable Holder<Item> pFallback)
    • convertToBoolean

      public static boolean convertToBoolean(com.google.gson.JsonElement pJson, String pMemberName)
      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

      public static boolean getAsBoolean(com.google.gson.JsonObject pJson, String pMemberName)
      Gets the boolean value of the field on the JsonObject with the given name.
    • getAsBoolean

      public static boolean getAsBoolean(com.google.gson.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.
    • convertToDouble

      public static double convertToDouble(com.google.gson.JsonElement pJson, String pMemberName)
    • getAsDouble

      public static double getAsDouble(com.google.gson.JsonObject pJson, String pMemberName)
    • getAsDouble

      public static double getAsDouble(com.google.gson.JsonObject pJson, String pMemberName, double pFallback)
    • convertToFloat

      public static float convertToFloat(com.google.gson.JsonElement pJson, String pMemberName)
      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

      public static float getAsFloat(com.google.gson.JsonObject pJson, String pMemberName)
      Gets the float value of the field on the JsonObject with the given name.
    • getAsFloat

      public static float getAsFloat(com.google.gson.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.
    • convertToLong

      public static long convertToLong(com.google.gson.JsonElement pJson, String pMemberName)
      Gets a long from a JSON element and validates that the value is actually a number.
    • getAsLong

      public static long getAsLong(com.google.gson.JsonObject pJson, String pMemberName)
      Gets a long from a JSON element, throws an error if the member does not exist.
    • getAsLong

      public static long getAsLong(com.google.gson.JsonObject pJson, String pMemberName, long pFallback)
    • convertToInt

      public static int convertToInt(com.google.gson.JsonElement pJson, String pMemberName)
      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

      public static int getAsInt(com.google.gson.JsonObject pJson, String pMemberName)
      Gets the integer value of the field on the JsonObject with the given name.
    • getAsInt

      public static int getAsInt(com.google.gson.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.
    • convertToByte

      public static byte convertToByte(com.google.gson.JsonElement pJson, String pMemberName)
    • getAsByte

      public static byte getAsByte(com.google.gson.JsonObject pJson, String pMemberName)
    • getAsByte

      public static byte getAsByte(com.google.gson.JsonObject pJson, String pMemberName, byte pFallback)
    • convertToCharacter

      public static char convertToCharacter(com.google.gson.JsonElement pJson, String pMemberName)
    • getAsCharacter

      public static char getAsCharacter(com.google.gson.JsonObject pJson, String pMemberName)
    • getAsCharacter

      public static char getAsCharacter(com.google.gson.JsonObject pJson, String pMemberName, char pFallback)
    • convertToBigDecimal

      public static BigDecimal convertToBigDecimal(com.google.gson.JsonElement pJson, String pMemberName)
    • getAsBigDecimal

      public static BigDecimal getAsBigDecimal(com.google.gson.JsonObject pJson, String pMemberName)
    • getAsBigDecimal

      public static BigDecimal getAsBigDecimal(com.google.gson.JsonObject pJson, String pMemberName, BigDecimal pFallback)
    • convertToBigInteger

      public static BigInteger convertToBigInteger(com.google.gson.JsonElement pJson, String pMemberName)
    • getAsBigInteger

      public static BigInteger getAsBigInteger(com.google.gson.JsonObject pJson, String pMemberName)
    • getAsBigInteger

      public static BigInteger getAsBigInteger(com.google.gson.JsonObject pJson, String pMemberName, BigInteger pFallback)
    • convertToShort

      public static short convertToShort(com.google.gson.JsonElement pJson, String pMemberName)
    • getAsShort

      public static short getAsShort(com.google.gson.JsonObject pJson, String pMemberName)
    • getAsShort

      public static short getAsShort(com.google.gson.JsonObject pJson, String pMemberName, short pFallback)
    • convertToJsonObject

      public static com.google.gson.JsonObject convertToJsonObject(com.google.gson.JsonElement pJson, String pMemberName)
      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 pJson, String pMemberName)
    • getAsJsonObject

      @Nullable @Contract("_,_,!null->!null;_,_,null->_") public static com.google.gson.JsonObject getAsJsonObject(com.google.gson.JsonObject pJson, String pMemberName, @Nullable com.google.gson.JsonObject pFallback)
      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 pJson, String pMemberName)
      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 pJson, String pMemberName)
      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 pJson, String pMemberName, @Nullable com.google.gson.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 com.google.gson.JsonElement pJson, String pMemberName, com.google.gson.JsonDeserializationContext pContext, Class<? extends T> pAdapter)
    • getAsObject

      public static <T> T getAsObject(com.google.gson.JsonObject pJson, String pMemberName, com.google.gson.JsonDeserializationContext pContext, Class<? extends T> pAdapter)
    • getAsObject

      @Nullable @Contract("_,_,!null,_,_->!null;_,_,null,_,_->_") public static <T> T getAsObject(com.google.gson.JsonObject pJson, String pMemberName, @Nullable T pFallback, com.google.gson.JsonDeserializationContext pContext, Class<? extends T> pAdapter)
    • getType

      public static String getType(@Nullable com.google.gson.JsonElement pJson)
      Gets a human-readable description of the given JsonElement's type. For example: "a number (4)"
    • fromNullableJson

      @Nullable public static <T> T fromNullableJson(com.google.gson.Gson pGson, Reader pReader, Class<T> pAdapter, boolean pLenient)
    • fromJson

      public static <T> T fromJson(com.google.gson.Gson pGson, Reader pReader, Class<T> pAdapter, boolean pLenient)
    • fromNullableJson

      @Nullable public static <T> T fromNullableJson(com.google.gson.Gson pGson, Reader pReader, com.google.gson.reflect.TypeToken<T> pType, boolean pLenient)
    • fromJson

      public static <T> T fromJson(com.google.gson.Gson pGson, Reader pReader, com.google.gson.reflect.TypeToken<T> pType, boolean pLenient)
    • fromNullableJson

      @Nullable public static <T> T fromNullableJson(com.google.gson.Gson pGson, String pJson, com.google.gson.reflect.TypeToken<T> pType, boolean pLenient)
    • fromJson

      public static <T> T fromJson(com.google.gson.Gson pGson, String pJson, Class<T> pAdapter, boolean pLenient)
    • fromNullableJson

      @Nullable public static <T> T fromNullableJson(com.google.gson.Gson pGson, String pJson, Class<T> pAdapter, boolean pLenient)
    • fromJson

      public static <T> T fromJson(com.google.gson.Gson pGson, Reader pReader, com.google.gson.reflect.TypeToken<T> pType)
    • fromNullableJson

      @Nullable public static <T> T fromNullableJson(com.google.gson.Gson pGson, String pJson, com.google.gson.reflect.TypeToken<T> pType)
    • fromJson

      public static <T> T fromJson(com.google.gson.Gson pGson, Reader pReader, Class<T> pJsonClass)
    • fromJson

      public static <T> T fromJson(com.google.gson.Gson pGson, String pJson, Class<T> pAdapter)
    • parse

      public static com.google.gson.JsonObject parse(String pJson, boolean pLenient)
    • parse

      public static com.google.gson.JsonObject parse(Reader pReader, boolean pLenient)
    • parse

      public static com.google.gson.JsonObject parse(String pJson)
    • parse

      public static com.google.gson.JsonObject parse(Reader pReader)
    • parseArray

      public static com.google.gson.JsonArray parseArray(String pString)
    • parseArray

      public static com.google.gson.JsonArray parseArray(Reader pReader)
    • toStableString

      public static String toStableString(com.google.gson.JsonElement pJson)
    • writeValue

      public static void writeValue(com.google.gson.stream.JsonWriter pWriter, @Nullable com.google.gson.JsonElement pJsonElement, @Nullable Comparator<String> pSorter) throws IOException
      Throws:
      IOException
    • sortByKeyIfNeeded

      private static Collection<Map.Entry<String,com.google.gson.JsonElement>> sortByKeyIfNeeded(Collection<Map.Entry<String,com.google.gson.JsonElement>> pEntries, @Nullable Comparator<String> pSorter)