@Override
    public HttpRequest apply(HttpRequest httpRequest) {
        if (!(httpRequest.getBody() instanceof RequestMessage)) {
            throw new IllegalArgumentException("Only RequestMessage serialization is supported");
        }

        final RequestMessage request = (RequestMessage) httpRequest.getBody();
        final ByteBuf requestBuf;
        try {
            requestBuf = serializer.serializeRequestAsBinary(request, ByteBufAllocator.DEFAULT);
        } catch (SerializationException se) {
            throw new RuntimeException(new ResponseException(HttpResponseStatus.BAD_REQUEST, String.format(
                    "An error occurred during serialization of this request [%s] - it could not be sent to the server - Reason: %s",
                    request, se)));
        }

        // Convert from ByteBuf to bytes[] because that's what the final request body should contain.
        final byte[] requestBytes = ByteBufUtil.getBytes(requestBuf);
        requestBuf.release();

        httpRequest.setBody(requestBytes);
        httpRequest.headers().put(HttpRequest.Headers.CONTENT_TYPE, serializer.mimeTypesSupported()[0]);

        return httpRequest;
    }
A {@link RequestInterceptor} that serializes the request body usng the provided {@link MessageSerializer}. This
interceptor should be run before other interceptors that need to calculate values based on the request body.
gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/interceptor/PayloadSerializingInterceptor.java