Class JsonObjectWrapper

java.lang.Object
net.pl3x.map.core.markers.JsonObjectWrapper

public class JsonObjectWrapper extends Object
Represents a wrapped JsonObject with extra 'addProperty' methods, because Google made it a final class for some weird reason.

Null values cannot be added to this JsonObject, they will simply be ignored when added.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty JsonObjectWrapper.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(String property, com.google.gson.JsonElement value)
    Adds a member, which is a name-value pair, to self.
    void
    addProperty(@NotNull String property, @Nullable Enum<?> value)
    Convenience method to add a primitive member.
    void
    addProperty(@NotNull String property, @Nullable List<? extends @NotNull JsonSerializable> value)
    Convenience method to add a primitive member.
    void
    addProperty(@NotNull String property, @Nullable JsonSerializable value)
    Convenience method to add a primitive member.
    void
    addProperty(@NotNull String property, @Nullable Option<?> value)
    Convenience method to add a primitive member.
    void
    addProperty(String property, Boolean value)
    Convenience method to add a boolean member.
    void
    addProperty(String property, Character value)
    Convenience method to add a char member.
    void
    addProperty(String property, Number value)
    Convenience method to add a primitive member.
    void
    addProperty(String property, String value)
    Convenience method to add a primitive member.
    com.google.gson.JsonObject
    Creates a deep copy of this element and all its children
    Set<Map.Entry<String,com.google.gson.JsonElement>>
    Returns a set of members of this object.
    boolean
     
    com.google.gson.JsonElement
    get(String memberName)
    Returns the member with the specified name.
    com.google.gson.JsonArray
    getAsJsonArray(String memberName)
    Convenience method to get the specified member as a JsonArray.
    com.google.gson.JsonObject
    getAsJsonObject(String memberName)
    Convenience method to get the specified member as a JsonObject.
    com.google.gson.JsonPrimitive
    Convenience method to get the specified member as a JsonPrimitive element.
    @NotNull com.google.gson.JsonObject
    Get the underlying JsonObject.
    boolean
    has(String memberName)
    Convenience method to check if a member with the specified name is present in this object.
    int
     
    Returns a set of members key values.
    com.google.gson.JsonElement
    remove(String property)
    Removes the property from this JsonObject.
    int
    Returns the number of key/value pairs in the object.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JsonObjectWrapper

      public JsonObjectWrapper()
      Creates an empty JsonObjectWrapper.
  • Method Details

    • getJsonObject

      @NotNull public @NotNull com.google.gson.JsonObject getJsonObject()
      Get the underlying JsonObject.
      Returns:
      JsonObject
    • addProperty

      public void addProperty(@NotNull @NotNull String property, @Nullable @Nullable Enum<?> value)
      Convenience method to add a primitive member. The specified value is converted to a JsonPrimitive of String.
      Parameters:
      property - name of the member.
      value - the enum value associated with the member.
    • addProperty

      public void addProperty(@NotNull @NotNull String property, @Nullable @Nullable JsonSerializable value)
      Convenience method to add a primitive member. The specified value is converted to a JsonPrimitive of String.
      Parameters:
      property - name of the member.
      value - the json serializable value associated with the member.
    • addProperty

      public void addProperty(@NotNull @NotNull String property, @Nullable @Nullable Option<?> value)
      Convenience method to add a primitive member. The specified value is converted to a JsonPrimitive of String.
      Parameters:
      property - name of the member.
      value - the option value associated with the member.
    • addProperty

      public void addProperty(@NotNull @NotNull String property, @Nullable @Nullable List<? extends @NotNull JsonSerializable> value)
      Convenience method to add a primitive member. The specified value is converted to a JsonPrimitive of String.
      Parameters:
      property - name of the member.
      value - the value associated with the member.
    • addProperty

      public void addProperty(String property, String value)
      Convenience method to add a primitive member. The specified value is converted to a JsonPrimitive of String.
      Parameters:
      property - name of the member.
      value - the string value associated with the member.
    • addProperty

      public void addProperty(String property, Number value)
      Convenience method to add a primitive member. The specified value is converted to a JsonPrimitive of Number.
      Parameters:
      property - name of the member.
      value - the number value associated with the member.
    • addProperty

      public void addProperty(String property, Boolean value)
      Convenience method to add a boolean member. The specified value is converted to a JsonPrimitive of Boolean.
      Parameters:
      property - name of the member.
      value - the boolean value associated with the member.
    • addProperty

      public void addProperty(String property, Character value)
      Convenience method to add a char member. The specified value is converted to a JsonPrimitive of Character.
      Parameters:
      property - name of the member.
      value - the number value associated with the member.
    • add

      public void add(String property, com.google.gson.JsonElement value)
      Adds a member, which is a name-value pair, to self. The name must be a String, but the value can be an arbitrary JsonElement, thereby allowing you to build a full tree of JsonElements rooted at this node.
      Parameters:
      property - name of the member.
      value - the member object.
    • remove

      public com.google.gson.JsonElement remove(String property)
      Removes the property from this JsonObject.
      Parameters:
      property - name of the member that should be removed.
      Returns:
      the JsonElement object that is being removed.
      Since:
      1.3
    • entrySet

      public Set<Map.Entry<String,com.google.gson.JsonElement>> entrySet()
      Returns a set of members of this object. The set is ordered, and the order is in which the elements were added.
      Returns:
      a set of members of this object.
    • keySet

      public Set<String> keySet()
      Returns a set of members key values.
      Returns:
      a set of member keys as Strings
      Since:
      2.8.1
    • size

      public int size()
      Returns the number of key/value pairs in the object.
      Returns:
      the number of key/value pairs in the object.
    • has

      public boolean has(String memberName)
      Convenience method to check if a member with the specified name is present in this object.
      Parameters:
      memberName - name of the member that is being checked for presence.
      Returns:
      true if there is a member with the specified name, false otherwise.
    • get

      public com.google.gson.JsonElement get(String memberName)
      Returns the member with the specified name.
      Parameters:
      memberName - name of the member that is being requested.
      Returns:
      the member matching the name. Null if no such member exists.
    • getAsJsonPrimitive

      public com.google.gson.JsonPrimitive getAsJsonPrimitive(String memberName)
      Convenience method to get the specified member as a JsonPrimitive element.
      Parameters:
      memberName - name of the member being requested.
      Returns:
      the JsonPrimitive corresponding to the specified member.
    • getAsJsonArray

      public com.google.gson.JsonArray getAsJsonArray(String memberName)
      Convenience method to get the specified member as a JsonArray.
      Parameters:
      memberName - name of the member being requested.
      Returns:
      the JsonArray corresponding to the specified member.
    • getAsJsonObject

      public com.google.gson.JsonObject getAsJsonObject(String memberName)
      Convenience method to get the specified member as a JsonObject.
      Parameters:
      memberName - name of the member being requested.
      Returns:
      the JsonObject corresponding to the specified member.
    • deepCopy

      public com.google.gson.JsonObject deepCopy()
      Creates a deep copy of this element and all its children
      Since:
      2.8.2
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object