mirror of
https://github.com/AXOLOTsh/RegistryLib.git
synced 2026-06-02 09:46:33 +03:00
29 lines
901 B
Java
29 lines
901 B
Java
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());
|
|
}
|
|
}
|