Class JsonUtil

java.lang.Object
com.mewna.catnip.util.JsonUtil

public final class JsonUtil extends Object
  • Field Details

  • Method Details

    • stringifySnowflakes

      @Nonnull public static com.grack.nanojson.JsonObject stringifySnowflakes(@Nonnull com.grack.nanojson.JsonObject json)
      Converts all snowflakes in the passed-in JsonObject to strings. This method will recursively traverse a JsonObject, looking for any idAsLong keys, and will replace them with stringified versions.

      This method changes the JSON object that is passed in.

      Parameters:
      json - The JSON object to stringify snowflakes in.
      Returns:
      The JSON object, with snowflakes longs replaced with strings.
    • destringifySnowflakes

      @Nonnull public static com.grack.nanojson.JsonObject destringifySnowflakes(@Nonnull com.grack.nanojson.JsonObject json)
      Converts all snowflakes in the passed-in JsonObject from strings to longs. This method will recursively traverse a JsonObject, looking for any idAsLong keys, and will replace them with destringified versions.

      This method changes the JSON object that is passed in.

      Parameters:
      json - The JSON object to destringify snowflakes in.
      Returns:
      The JSON object, with snowflakes strings replaced with longs.
    • toList

      @Nonnull @CheckReturnValue public static <T> List<T> toList(@Nullable com.grack.nanojson.JsonArray array, @Nonnull Function<com.grack.nanojson.JsonObject,T> mapper)
    • toListFromCache

      @Nonnull @CheckReturnValue public static <T> List<T> toListFromCache(@Nullable com.grack.nanojson.JsonArray array, @Nonnull Function<String,T> mapper)
    • toSet

      @Nonnull @CheckReturnValue public static <T> Set<T> toSet(@Nullable com.grack.nanojson.JsonArray array, @Nonnull Function<com.grack.nanojson.JsonObject,T> mapper)
    • toMutableSet

      @Nonnull @CheckReturnValue public static <T> Set<T> toMutableSet(@Nullable com.grack.nanojson.JsonArray array, @Nonnull Function<com.grack.nanojson.JsonObject,T> mapper)
    • toMap

      @Nonnull @CheckReturnValue public static <T> Map<String,T> toMap(@Nullable com.grack.nanojson.JsonArray array, @Nonnull Function<com.grack.nanojson.JsonObject,String> keyFunction, @Nonnull Function<com.grack.nanojson.JsonObject,T> mapper)
    • toStringList

      @Nonnull @CheckReturnValue public static List<String> toStringList(@Nullable com.grack.nanojson.JsonArray array)
    • stringListToTypedList

      @Nonnull @CheckReturnValue public static <T> List<T> stringListToTypedList(@Nullable com.grack.nanojson.JsonArray array, @Nonnull Function<String,T> mapper)
    • toStringSet

      @Nonnull @CheckReturnValue public static Set<String> toStringSet(@Nullable com.grack.nanojson.JsonArray array)
    • toSnowflakeList

      @Nonnull @CheckReturnValue public static List<Long> toSnowflakeList(@Nullable com.grack.nanojson.JsonArray array)
    • mapObjectContents

      @Nonnull @CheckReturnValue public static <T> Function<com.grack.nanojson.JsonArray,List<T>> mapObjectContents(@Nonnull Function<com.grack.nanojson.JsonObject,T> builder)
    • encodePrettily

      public static String encodePrettily(com.grack.nanojson.JsonObject data)