Class BukkitJSONSerializer

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected @NotNull com.google.gson.Gson gson  
      static BukkitJSONSerializer INSTANCE  
      protected @NotNull com.google.gson.JsonParser parser  
      static java.lang.String TYPE_KEY  
    • Constructor Summary

      Constructors 
      Constructor Description
      BukkitJSONSerializer​(@NotNull com.google.gson.Gson gson, @NotNull com.google.gson.JsonParser parser)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static @NotNull BukkitJSONSerializer create()  
      static @NotNull BukkitJSONSerializer create​(@NotNull com.google.gson.Gson gson)  
      static @NotNull BukkitJSONSerializer create​(@NotNull com.google.gson.Gson gson, @NotNull com.google.gson.JsonParser parser)  
      java.lang.Object deserializeJSON​(@Nullable java.lang.String json)
      Deserializes a ConfigurationSerializable object from JSON.
      <T extends org.bukkit.configuration.serialization.ConfigurationSerializable>
      T
      deserializeJSON​(@Nullable java.lang.String json, @NotNull java.lang.Class<T> typeClazz)
      Deserializes a ConfigurationSerializable object from Map.
      <T extends org.bukkit.configuration.serialization.ConfigurationSerializable>
      T
      deserializeJSON​(@Nullable java.lang.String json, @NotNull java.lang.Class<T> typeClazz, T defaultValue)
      Deserializes a ConfigurationSerializable object from Map.
      org.bukkit.configuration.serialization.ConfigurationSerializable deserializeJSON​(@Nullable java.lang.String json, @Nullable org.bukkit.configuration.serialization.ConfigurationSerializable defaultValue)
      Deserializes a ConfigurationSerializable object from JSON.
      static @NotNull BukkitJSONSerializer get()  
      protected java.util.Map<java.lang.String,​java.lang.Object> jsonToMap​(com.google.gson.JsonObject object)  
      protected java.util.Map<java.lang.String,​java.lang.Object> jsonToMap​(java.lang.String json)  
      protected java.util.Map<java.lang.String,​java.lang.Object> parseMap​(java.util.Map<?,​?> map)  
      <T extends org.bukkit.configuration.serialization.ConfigurationSerializable>
      java.lang.String
      serializeToJSON​(T value)
      Serializes a ConfigurationSerializable object to JSON.
      <T extends org.bukkit.configuration.serialization.ConfigurationSerializable>
      java.util.Map<java.lang.String,​java.lang.Object>
      serializeToMap​(T value)
      Serializes a ConfigurationSerializable object to Map.
      • Methods inherited from class java.lang.Object

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

      • gson

        @NotNull
        protected final @NotNull com.google.gson.Gson gson
      • parser

        @NotNull
        protected final @NotNull com.google.gson.JsonParser parser
    • Constructor Detail

      • BukkitJSONSerializer

        public BukkitJSONSerializer​(@NotNull
                                    @NotNull com.google.gson.Gson gson,
                                    @NotNull
                                    @NotNull com.google.gson.JsonParser parser)
    • Method Detail

      • create

        @NotNull
        public static @NotNull BukkitJSONSerializer create​(@NotNull
                                                           @NotNull com.google.gson.Gson gson)
      • create

        @NotNull
        public static @NotNull BukkitJSONSerializer create​(@NotNull
                                                           @NotNull com.google.gson.Gson gson,
                                                           @NotNull
                                                           @NotNull com.google.gson.JsonParser parser)
      • serializeToMap

        public <T extends org.bukkit.configuration.serialization.ConfigurationSerializable> java.util.Map<java.lang.String,​java.lang.Object> serializeToMap​(T value)
        Serializes a ConfigurationSerializable object to Map.
        Type Parameters:
        T - ConfigurationSerializable object type.
        Parameters:
        value - object to serialize.
        Returns:
        Map containing serialized data
      • serializeToJSON

        public <T extends org.bukkit.configuration.serialization.ConfigurationSerializable> java.lang.String serializeToJSON​(T value)
        Serializes a ConfigurationSerializable object to JSON.
        Type Parameters:
        T - ConfigurationSerializable object type.
        Parameters:
        value - object to serialize.
        Returns:
        JSON string containing serialized data.
      • deserializeJSON

        @Contract("null->null")
        public java.lang.Object deserializeJSON​(@Nullable
                                                @Nullable java.lang.String json)
        Deserializes a ConfigurationSerializable object from JSON.
        Parameters:
        json - JSON string to deserialize.
        Returns:
        Deserialized object.
      • deserializeJSON

        @Contract("_,!null->!null; null,null->null")
        public org.bukkit.configuration.serialization.ConfigurationSerializable deserializeJSON​(@Nullable
                                                                                                @Nullable java.lang.String json,
                                                                                                @Nullable
                                                                                                @Nullable org.bukkit.configuration.serialization.ConfigurationSerializable defaultValue)
        Deserializes a ConfigurationSerializable object from JSON.
        Parameters:
        json - JSON string to deserialize.
        defaultValue - default value to return if json is null or failed to deserialize.
        Returns:
        Deserialized object.
      • deserializeJSON

        @Nullable
        public <T extends org.bukkit.configuration.serialization.ConfigurationSerializable> T deserializeJSON​(@Nullable
                                                                                                              @Nullable java.lang.String json,
                                                                                                              @NotNull
                                                                                                              @NotNull java.lang.Class<T> typeClazz)
        Deserializes a ConfigurationSerializable object from Map.
        Type Parameters:
        T - ConfigurationSerializable object type.
        Parameters:
        json - JSON string to deserialize.
        typeClazz - type of object.
        Returns:
        Deserialized object.
      • deserializeJSON

        @Contract("_,_,!null->!null; null,_,null->null")
        public <T extends org.bukkit.configuration.serialization.ConfigurationSerializable> T deserializeJSON​(@Nullable
                                                                                                              @Nullable java.lang.String json,
                                                                                                              @NotNull
                                                                                                              @NotNull java.lang.Class<T> typeClazz,
                                                                                                              @Nullable
                                                                                                              T defaultValue)
        Deserializes a ConfigurationSerializable object from Map.
        Type Parameters:
        T - ConfigurationSerializable object type.
        Parameters:
        json - JSON string to deserialize.
        typeClazz - type of object.
        defaultValue - default value to return if json is null or failed to deserialize.
        Returns:
        Deserialized object.
      • jsonToMap

        protected java.util.Map<java.lang.String,​java.lang.Object> jsonToMap​(java.lang.String json)
      • jsonToMap

        protected java.util.Map<java.lang.String,​java.lang.Object> jsonToMap​(com.google.gson.JsonObject object)
      • parseMap

        protected java.util.Map<java.lang.String,​java.lang.Object> parseMap​(java.util.Map<?,​?> map)