### Question:
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); } } PeriodicPaymentInitiationMultipartBodyHttpMessageConverter(ObjectMapper objectMapper); @Override List<MediaType> getSupportedMediaTypes(); @Override boolean canRead(Class<?> clazz, @Nullable MediaType mediaType); @Override PeriodicPaymentInitiationMultipartBody read(
        Class<? extends PeriodicPaymentInitiationMultipartBody> clazz,
        HttpInputMessage inputMessage
    ); @Override boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType); @Override void write(PeriodicPaymentInitiationMultipartBody body,
                      MediaType contentType,
                      HttpOutputMessage outputMessage);  }### Answer:
@Test void write() throws IOException { PeriodicPaymentInitiationMultipartBodyHttpMessageConverter converter = new PeriodicPaymentInitiationMultipartBodyHttpMessageConverter(WebMvcConfig.newConfiguredObjectMapper()) { @Override protected byte[] generateMultipartBoundary() { return "r3kG3pY8rRua0pHMuWCLa2TESC--Kne".getBytes(); } }; PeriodicPaymentInitiationMultipartBody body = new PeriodicPaymentInitiationMultipartBody(); body.setXml_sct("<xml></xml>"); PeriodicPaymentInitiationXmlPart2StandingorderTypeJson json = new PeriodicPaymentInitiationXmlPart2StandingorderTypeJson(); json.setDayOfExecution(DayOfExecution._2); json.setFrequency(FrequencyCode.QUARTERLY); json.setStartDate(LocalDate.of(2020, 1, 1)); json.setEndDate(LocalDate.of(2021, 1, 1)); json.setExecutionRule(ExecutionRule.PRECEDING); body.setJson_standingorderType(json); MockHttpOutputMessage out = new MockHttpOutputMessage(); converter.write(body, null, out); assertThat(out.getBodyAsString()) .isEqualTo("--r3kG3pY8rRua0pHMuWCLa2TESC--Kne\r\n" + "Content-Disposition: form-data; name=\"xml_sct\"\r\n" + "Content-Type: application/xml\r\n" + "Content-Length: 11\r\n" + "\r\n" + "<xml></xml>\r\n" + "--r3kG3pY8rRua0pHMuWCLa2TESC--Kne\r\n" + "Content-Disposition: form-data; name=\"json_standingorderType\"\r\n" + "Content-Type: application/json\r\n" + "\r\n" + "{\n" + " \"startDate\" : \"2020-01-01\",\n" + " \"endDate\" : \"2021-01-01\",\n" + " \"executionRule\" : \"preceding\",\n" + " \"frequency\" : \"Quarterly\",\n" + " \"dayOfExecution\" : \"2\"\n" + "}\r\n" + "--r3kG3pY8rRua0pHMuWCLa2TESC--Kne--\r\n"); }