Class PersistentDataSerializer
java.lang.Object
com.jeff_media.persistentdataserializer.PersistentDataSerializer
Utility class to serialize and deserialize for
PersistentDataContainers-
Method Summary
Modifier and TypeMethodDescriptionstatic PersistentDataContainerfromJson(String serializedPdc, PersistentDataAdapterContext context) Deserializes aPersistentDataContainerfrom JSON and saves it to a newPersistentDataContainercreated in the given contextstatic PersistentDataContainerfromJson(String serializedPdc, PersistentDataContainer targetPdc) Deserializes aPersistentDataContainerfrom JSON and saves it to the given targetPersistentDataContainerstatic PersistentDataContainerfromMapList(List<Map<?, ?>> serializedPdc, PersistentDataAdapterContext context) Deserializes aPersistentDataContainerfrom a list of maps and saves it to the given targetPersistentDataContainerstatic PersistentDataContainerfromMapList(List<Map<?, ?>> serializedPdc, PersistentDataContainer targetPdc) Deserializes aPersistentDataContainerfrom a list of maps and saves it to the given targetPersistentDataContainerstatic PersistentDataType<?,?> Gets the properPersistentDataTypefor the givenNamespacedKeystatic StringSerializes aPersistentDataContainerto JSONSerializes aPersistentDataContainerto a list of maps
-
Method Details
-
getPrimitivePersistentDataType
public static PersistentDataType<?,?> getPrimitivePersistentDataType(@NotNull PersistentDataContainer pdc, @NotNull NamespacedKey key) throws IllegalArgumentException Gets the properPersistentDataTypefor the givenNamespacedKey- Parameters:
pdc- PersistentDataContainerkey- NamespacedKey- Returns:
- PrimitivePersistentDataType
- Throws:
IllegalArgumentException- if no native PrimitivePersistentDataType was found. (This should never happen.)
-
toMapList
@NotNull @Contract(value="_ -> new", pure=true) public static List<Map<?,?>> toMapList(@NotNull PersistentDataContainer pdc) Serializes aPersistentDataContainerto a list of maps- Parameters:
pdc- PersistentDataContainer- Returns:
- serialized PersistentDataContainer
-
fromMapList
@NotNull @Contract("_, _ -> param2") public static PersistentDataContainer fromMapList(@NotNull List<Map<?, ?>> serializedPdc, @NotNull PersistentDataContainer targetPdc) Deserializes aPersistentDataContainerfrom a list of maps and saves it to the given targetPersistentDataContainer- Parameters:
serializedPdc- serialized PersistentDataContainertargetPdc- target PersistentDataContainer- Returns:
- deserialized PersistentDataContainer
-
fromMapList
@NotNull @Contract(value="_, _ -> new", pure=true) public static PersistentDataContainer fromMapList(@NotNull List<Map<?, ?>> serializedPdc, @NotNull PersistentDataAdapterContext context) Deserializes aPersistentDataContainerfrom a list of maps and saves it to the given targetPersistentDataContainer- Parameters:
serializedPdc- serialized PersistentDataContainercontext- PersistentDataAdapterContext- Returns:
- deserialized PersistentDataContainer
-
toJson
@Contract(value="_ -> new", pure=true) @NotNull public static String toJson(@NotNull PersistentDataContainer pdc) Serializes aPersistentDataContainerto JSON- Parameters:
pdc- PersistentDataContainer- Returns:
- JSON string
-
fromJson
@Contract("_, _ -> param2") @NotNull public static PersistentDataContainer fromJson(@NotNull String serializedPdc, @NotNull PersistentDataContainer targetPdc) throws com.google.gson.JsonSyntaxException Deserializes aPersistentDataContainerfrom JSON and saves it to the given targetPersistentDataContainer- Parameters:
serializedPdc- serialized PersistentDataContainertargetPdc- target PersistentDataContainer- Returns:
- deserialized PersistentDataContainer
- Throws:
com.google.gson.JsonSyntaxException- if the JSON is malformed
-
fromJson
@Contract(value="_, _ -> new", pure=true) @NotNull public static PersistentDataContainer fromJson(@NotNull String serializedPdc, @NotNull PersistentDataAdapterContext context) throws com.google.gson.JsonSyntaxException Deserializes aPersistentDataContainerfrom JSON and saves it to a newPersistentDataContainercreated in the given context- Parameters:
serializedPdc- serialized PersistentDataContainercontext- PersistentDataAdapterContext- Returns:
- deserialized PersistentDataContainer
- Throws:
com.google.gson.JsonSyntaxException- if the JSON is malformed
-