1
mirror of https://github.com/CarmJos/BukkitJSONSerializer.git synced 2024-09-16 20:05:57 +00:00
A JSON serialize/deserialize util for bukkit's ConfigurationSerialization.
Go to file
dependabot[bot] 5473b2cad0 build(deps): bump org.apache.maven.plugins:maven-javadoc-plugin
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.8.0 to 3.10.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.8.0...maven-javadoc-plugin-3.10.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-14 22:48:14 +08:00
.github ci: remove readme deploy 2022-06-07 07:06:25 +08:00
src fix(deserialize): try to fix gson number deserialize problem. 2022-07-30 01:44:57 +08:00
.gitignore feat: A lightweight JSON serializer 2022-06-07 06:59:26 +08:00
LICENSE feat: A lightweight JSON serializer 2022-06-07 06:59:26 +08:00
pom.xml build(deps): bump org.apache.maven.plugins:maven-javadoc-plugin 2024-09-14 22:48:14 +08:00
README.md Update README.md 2022-12-10 11:36:47 +08:00

BukkitJSONSerializer

version License workflow CodeFactor CodeSize

A JSON serialize/deserialize util for bukkit's ConfigurationSerialization.

Usage

Basic usage

First, we should get the serializer instance or create a new one.

BukkitJSONSerializer serializer = BukkitJSONSerializer.get();

Then, we could use serializeToJSON(ConfigurationSerializable) to serialize a object to JSON.

Location location = new Location(Bukkit.getWorlds().get(0), -100.5, 100, 105.5);
String serialized = serializer.serializeToJSON(location);
// -> {"world":"world","x":-100.5,"y":100,"z":105.5,"yaw":0.0,"pitch":0.0}

When we need to read the object, just use deserializeJSON(json,typeClass) to deserialize the JSON string.

Location location = serializer.deserializeJSON(json, Location.class);
// Location{world=world, x=-100.5, y=100, z=105.5, pitch=0.0, yaw=0.0}

Or use deserializeSON(json,typeClass,defaultValue) if we need a default value.

JSONSerializable class

This project provided an interface JSONSerializable which provided a default method to serialize itself to JSON.

public interface JSONSerializable extends ConfigurationSerializable {

    default @NotNull String serializeToJSON() {
        return BukkitJSONSerializer.serializeToJSON(this);
    }

}

Dependency Usage

Maven dependency

<project>
    <repositories>

        <repository>
            <!--Using central repository-->
            <id>maven</id>
            <name>Maven Central</name>
            <url>https://repo1.maven.org/maven2</url>
        </repository>

        <repository>
            <!--Using github repository-->
            <id>BukkitJSONSerializer</id>
            <url>https://raw.githubusercontent.com/CarmJos/BukkitJSONSerializer/repo/</url>
        </repository>

    </repositories>

    <dependencies>

        <dependency>
            <groupId>cc.carm.lib</groupId>
            <artifactId>bukkitjsonserializer</artifactId>
            <version>[LATEST RELEASE]</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

</project>
Gradle dependency
repositories {

    mavenCentral() // Using central repository.

    // Using github repositories.
    maven { url 'https://raw.githubusercontent.com/CarmJos/BukkitJSONSerializer/repo/' }

}

dependencies {
    api "cc.carm.lib:bukkitjsonserializer:[LATEST RELEASE]"
}

Open Source License.

The project using GNU LESSER GENERAL PUBLIC LICENSE .