mirror of
https://github.com/AXOLOTsh/RegistryLib.git
synced 2026-06-02 09:46:33 +03:00
feature: add project files
This commit is contained in:
28
src/main/java/io/github/axolotsh/registrylib/KeyAdapter.java
Normal file
28
src/main/java/io/github/axolotsh/registrylib/KeyAdapter.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package io.github.axolotsh.registrylib;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
|
||||
/**
|
||||
* Overrides the serialization logic of {@link Key}, causing it to be serialized
|
||||
* and deserialized as {@link String}.
|
||||
*/
|
||||
public class KeyAdapter implements JsonSerializer<Key>, JsonDeserializer<Key> {
|
||||
@Override
|
||||
public JsonElement serialize(Key src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
|
||||
return Key.key(json.getAsString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user