ru.cwcode.tkach.config.paper.jackson.modules.ItemStackSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of PaperConfig Show documentation
Show all versions of PaperConfig Show documentation
CWConfig library platform for Paper (Minecraft)
package ru.cwcode.tkach.config.paper.jackson.modules;
import ru.cwcode.tkach.config.relocate.com.fasterxml.jackson.core.JsonGenerator;
import ru.cwcode.tkach.config.relocate.com.fasterxml.jackson.databind.BeanProperty;
import ru.cwcode.tkach.config.relocate.com.fasterxml.jackson.databind.JsonSerializer;
import ru.cwcode.tkach.config.relocate.com.fasterxml.jackson.databind.SerializerProvider;
import ru.cwcode.tkach.config.relocate.com.fasterxml.jackson.databind.ser.ContextualSerializer;
import org.bukkit.inventory.ItemStack;
import ru.cwcode.cwutils.items.ItemStackUtils;
import ru.cwcode.tkach.config.annotation.Fancy;
import java.io.IOException;
public class ItemStackSerializer extends JsonSerializer implements ContextualSerializer {
boolean fancy;
@Override
public void serialize(ItemStack value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (fancy) {
gen.writeString(ItemStackUtils.toSNBT(value));
} else {
gen.writeBinary(value.serializeAsBytes());
}
}
@Override
public JsonSerializer> createContextual(SerializerProvider prov, BeanProperty property) {
fancy = property.getAnnotation(Fancy.class) != null;
return this;
}
}