使用 resttemplate Exchange 在 POST 请求正文中发送参数和列表

Send parameters and a list in body of POST request WIth resttemplate Exchange

您好,我必须使用这些参数 resttemplate.exchange 发送 POST 请求

{
"tipoPortafoglio": "string",
  "allegatiPratica": [
    {
      "fileName": "string",
      "body": "string",
      "mimeType": "string"
    }
  ]
}

我有一个名为

的映射 class
Public class CreateRichiesta { 
String tipoPortafoglio
Allegato  allegatiPratica    //<===== Custom type defined as JSON 
//Getter and setters

由于 customtype infact

,我无法使用 HashMap 将实体传递给 RestTemplate.Exchange
Map<String,String> input = new HashMap<>();
input.put("tipoPortafoglio", request.getTipoPortafoglio());
input.put("allegatiPratica", request.getAllegatiPratica()));

getAllegatiPratica 不是字符串类型而是 Allegato 类型

我该怎么办?谢谢大家

HttpEntity<CreateRichiesta> request = new HttpEntity<>(new CreateRichiesta());
ResponseEntity<CreateRichiestaResponse> responseEntityObj = restTemplate
     .exchange(resourceUrl, HttpMethod.POST, request, CreateRichiestaResponse.class);