У меня есть класс dto для взаимодействия с платежной системой api:
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
@Builder
@Getter
@Setter
public class PaymentSystemRequestDto {
@JsonProperty("order_id")
protected String orderId;
@JsonProperty("merchant_id")
protected String merchantId;
@JsonProperty("amount")
protected Long amount;
@JsonProperty("currency")
protected String currency;
@JsonProperty("version")
protected String version;
@JsonProperty("verification")
private Boolean verification = false;
@JsonProperty("verification_type")
private VerificationType verificationType;
public static class PaymentSystemRequestDtoBuilder {
public PaymentSystemRequestDtoBuilder amount(Long amount) {
this.amount = amount * 100;
return this;
}
public PaymentSystemRequestDtoBuilder cardRegistrationPayment() {
this.verification = true;
this.verificationType = VerificationType.AMOUNT;
return this;
}
}
}
Когда я отправляю запрос, основываясь на моем dto, у меня есть такое тело метода post:
{
"order_id": "a94f1d0d-21c5-4c2d-824d-d6c1875eaa30",
"merchant_id": "1234567",
"amount": 100,
"currency": "USD",
"version": "1.0",
}
Мне нужно обернуть тело в объект «запрос», чтобы тело выглядело так:
{
"request": {
"order_id": "a94f1d0d-21c5-4c2d-824d-d6c1875eaa30",
"merchant_id": "1234567",
"amount": 100,
"currency": "USD",
"version": "1.0",
}
}
, но без изменения функций сериализации / десериализации картографического объекта ( без использования аннотации @ JsonRootName )
Я пытался создать внутренний класс с помощью компоновщика, но он кажется надежным и сложным ... Есть ли способ справиться с этим простым?