public static void serializeByteBuffer(JsonGenerator generator, FieldBase field, ByteBuffer raw) {
        fieldNameIfNotNull(generator, field);

        final byte[] data = new byte[raw.remaining()];
        final int origPosition = raw.position();

        // base64encoder has no encode methods with offset and
        // limit, so no use trying to get at the backing array if
        // available anyway
        raw.get(data);
        raw.position(origPosition);

        wrapIOException(() -> generator.writeString(base64Encoder.encodeToString(data)));
    }
@author Steinar Knutsen
@author Vegard Sjonfjell
document/src/main/java/com/yahoo/document/json/JsonSerializationHelper.java