de.eldoria.jacksonbukkit.serializer.PaperItemStackSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of paper Show documentation
Show all versions of paper Show documentation
Module for serialization on Paper based servers
The newest version!
/*
* SPDX-License-Identifier: MIT
*
* Copyright (C) EldoriaRPG Team and Contributor
*/
package de.eldoria.jacksonbukkit.serializer;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import de.eldoria.jacksonbukkit.util.PaperFeatures;
import org.bukkit.inventory.ItemStack;
import java.io.IOException;
import java.util.Base64;
/**
* Class for serialization of {@link ItemStack} as {@code byte[]}.
*/
public class PaperItemStackSerializer extends LegacyItemStackSerializer {
@Override
public void serialize(ItemStack value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
if (PaperFeatures.HAS_SERIALIZE_AS_BYTES) {
gen.writeString(Base64.getEncoder().encodeToString(value.serializeAsBytes()));
} else {
super.serialize(value, gen, serializers);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy