发送参数和带有resttemplate Exchange的POST请求正文中的列表

问题描述 投票:0回答:1

嗨,我必须发送带有这些参数的resttemplate.exchange的POST请求

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

我有一个映射的类,称为

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

由于自定义类型的存在,我无法通过HashMap将实体传递给RestTemplate.Exchange。>

Map<String,String> input = new HashMap<>();
input.put("tipoPortafoglio", request.getTipoPortafoglio());
input.put("allegatiPratica", request.getAllegatiPratica()));

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

我该怎么办?感谢所有人

[嗨,我必须发送带有resttemplate.exchange的POST请求,这些请求带有这些参数{“ tipoPortafoglio”:“ string”,“ allegatiPratica”:[{“ fileName”:“ string”,“ body”:“ string”,.. 。

json spring web-services post resttemplate
1个回答
1
投票
HttpEntity<CreateRichiesta> request = new HttpEntity<>(new CreateRichiesta());
ResponseEntity<CreateRichiestaResponse> responseEntityObj = restTemplate.
     .exchange(resourceUrl, HttpMethod.POST, request, CreateRichiestaResponse.class);
© www.soinside.com 2019 - 2024. All rights reserved.