class PeriodicPaymentInitiationMultipartBodyHttpMessageConverter implements HttpMessageConverter<PeriodicPaymentInitiationMultipartBody> {

    @Override
    public void write(PeriodicPaymentInitiationMultipartBody body,
                      MediaType contentType,
                      HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {

        if (contentType == null) {
            contentType = MediaType.MULTIPART_FORM_DATA;
        }

        byte[] boundary = generateMultipartBoundary();
        Map<String, String> parameters = new LinkedHashMap<>(2);
        parameters.put("charset", this.charset.name());
        parameters.put("boundary", new String(boundary, StandardCharsets.US_ASCII));

        contentType = new MediaType(contentType, parameters);
        outputMessage.getHeaders().setContentType(contentType);

        if (outputMessage instanceof StreamingHttpOutputMessage) {
            StreamingHttpOutputMessage streamingOutputMessage = (StreamingHttpOutputMessage) outputMessage;
            streamingOutputMessage.setBody(outputStream -> {
                writeParts(outputStream, body, boundary);
                writeEnd(outputStream, boundary);
            });
        } else {
            writeParts(outputMessage.getBody(), body, boundary);
            writeEnd(outputMessage.getBody(), boundary);
        }
    }

    public  PeriodicPaymentInitiationMultipartBodyHttpMessageConverter(ObjectMapper objectMapper);

}