alef 0.25.37

Opinionated polyglot binding generator for Rust libraries
Documentation
/**
 * Serialises {@code byte[]} as a JSON array of integers.
 *
 * <p>Jackson's default serialiser encodes {@code byte[]} as a base64 string, but
 * Rust's {@code serde} for {@code Vec<u8>} expects {@code [72, 101, 108, ...]}.
 * Annotate any {@code byte[]} field sent to the FFI layer with
 * {@code @JsonSerialize(using = ByteArrayToIntArraySerializer.class)}.
 */
@SuppressWarnings("PMD")
public class ByteArrayToIntArraySerializer extends StdSerializer<byte[]> {
    /** Default constructor required by Jackson. */
    public ByteArrayToIntArraySerializer() {
        super(byte[].class);
    }

    @Override
    public void serialize(final byte[] value, final JsonGenerator gen,
            final SerializerProvider provider) throws java.io.IOException {
        gen.writeStartArray();
        for (byte b : value) {
            gen.writeNumber(b & 0xFF);
        }
        gen.writeEndArray();
    }
}