alef 0.76.0

Opinionated polyglot binding generator for Rust libraries
Documentation
/**
 * Serialises a millisecond count as the JSON shape Rust's serde derives for
 * {@code std::time::Duration} ({@code {"secs": <u64>, "nanos": <u32>}}).
 *
 * <p>Jackson's default serialisation of a {@code Long} field is a bare number, but the
 * Rust FFI layer deserializes struct JSON directly into the real {@code Duration}-typed
 * core struct, which requires this object shape. Annotate any {@code Long} field that
 * represents a Rust {@code Duration} with
 * {@code @JsonSerialize(using = DurationMillisSerializer.class)}.
 */
@SuppressWarnings("PMD")
public class DurationMillisSerializer extends JsonSerializer<Long> {

    @Override
    public void serialize(final Long value, final JsonGenerator gen,
            final SerializerProvider provider) throws java.io.IOException {
        gen.writeStartObject();
        gen.writeNumberField("secs", value / 1000L);
        gen.writeNumberField("nanos", (int) ((value % 1000L) * 1_000_000L));
        gen.writeEndObject();
    }
}