Skip to content

mfnalex/JsonConfigurationSerialization

Repository files navigation

JSON Serializer/Deserializer for Spigot's ConfigurationSerializable

Javadocs Discord Donate

Simple library to serialize and deserialize Spigot's ConfigurationSerializable objects to and from JSON. Compatible with all Spigot versions.

Usage

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);

Maven dependency

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.

Note for ancient Spigot versions

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)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages