Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/carmjos/bukkitjsonserializer
A JSON serialize/deserialize util for bukkit's ConfigurationSerialization.
https://github.com/carmjos/bukkitjsonserializer
bukkit deserialization json serialization spigot
Last synced: 4 months ago
JSON representation
A JSON serialize/deserialize util for bukkit's ConfigurationSerialization.
- Host: GitHub
- URL: https://github.com/carmjos/bukkitjsonserializer
- Owner: CarmJos
- License: lgpl-3.0
- Created: 2022-06-06T21:24:55.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-09-27T16:56:03.000Z (4 months ago)
- Last Synced: 2024-09-28T12:03:20.677Z (4 months ago)
- Topics: bukkit, deserialization, json, serialization, spigot
- Language: Java
- Homepage:
- Size: 450 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# BukkitJSONSerializer
[![version](https://img.shields.io/github/v/release/CarmJos/BukkitJSONSerializer)](https://github.com/CarmJos/BukkitJSONSerializer/releases)
[![License](https://img.shields.io/github/license/CarmJos/BukkitJSONSerializer)](https://www.gnu.org/licenses/lgpl-3.0.html)
[![workflow](https://github.com/CarmJos/BukkitJSONSerializer/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/CarmJos/BukkitJSONSerializer/actions/workflows/maven.yml)
[![CodeFactor](https://www.codefactor.io/repository/github/carmjos/BukkitJSONSerializer/badge)](https://www.codefactor.io/repository/github/carmjos/BukkitJSONSerializer)
![CodeSize](https://img.shields.io/github/languages/code-size/CarmJos/BukkitJSONSerializer)
![](https://visitor-badge.glitch.me/badge?page_id=BukkitJSONSerializer.readme)A JSON serialize/deserialize util for bukkit's ConfigurationSerialization.
## Usage
### Basic usage
First, we should get the serializer instance or create a new one.
```java
BukkitJSONSerializer serializer = BukkitJSONSerializer.get();
```Then, we could use `serializeToJSON(ConfigurationSerializable)` to serialize a object to JSON.
```jave
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.```java
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.
```java
public interface JSONSerializable extends ConfigurationSerializable {default @NotNull String serializeToJSON() {
return BukkitJSONSerializer.serializeToJSON(this);
}}
```## Dependency Usage
Maven dependency
```xml
maven
Maven Central
https://repo1.maven.org/maven2
BukkitJSONSerializer
https://raw.githubusercontent.com/CarmJos/BukkitJSONSerializer/repo/
cc.carm.lib
bukkitjsonserializer
[LATEST RELEASE]
compile
```
Gradle dependency
```groovy
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](https://www.gnu.org/licenses/lgpl-3.0.html) .