Simple library to serialize and deserialize Spigot's ConfigurationSerializable objects to and from JSON. Compatible with all Spigot versions.
You can either use the static utility methods to serialize to/from json Strings:
// Serializing
String serialized = JsonConfigurationSerialization.serialize(someItemStack);
// Deserializing
ItemStack deserialized = (ItemStack) JsonConfigurationSerialization.deserialize(serialized);
Or you can use the ConfigurationSerializableTypeHierarchyAdapter directly with Gson:
Gson gson = new GsonBuilder().registerTypeHierarchyAdapter(ConfigurationSerializable.class, JsonConfigurationSerialization.TYPE_HIERARCHY_ADAPTER).create();
String serialized = gson.toJson(someItemStack);
ItemStack deserialized = gson.fromJson(serialized, ItemStack.class);
The dependency is available on Maven Central:
<dependency>
<groupId>com.jeff-media</groupId>
<artifactId>json-configuration-serialization</artifactId>
<version>1.1.4</version>
</dependency>
Must be shaded into your plugin jar.
If your version of Spigot does not provide Gson on its classpath, you need to shade a compatible version of it yourself (e.g. com.google.code.gson:gson:2.10.1)