Автоматизация указанного ниже запроса REST API Post (полезная нагрузка ниже) с шаблоном построителя - невозможно установить только первый элемент списка - PullRequest
0 голосов
/ 14 июля 2020

// Обязательная полезная нагрузка Post-запроса:

{
  "paymentId":"787298",
  "reconciliationRecordInvoices" :[
  {
    "invoiceNumber"      :  "1003",
    "supplierEmail"      :  "gs1003@mastercard.com",
    "purchaseOrderNumber" :  "PO102",
    "accountNumber"      :  "ACC123",
    "currency"        :  "EUR",
    "invoiceAmount"      :  "35.12",
    "invoiceDate"      :  "2020-07-01",
        "amountPaid"      :  "34.21",

               },
    {
     "invoiceNumber"      :  "1004",
    "supplierEmail"      :  "sample@mailmastercard.com",
    "purchaseOrderNumber"  :  "PO103",
    "accountNumber"      :  "ACC143",
    "currency"        :  "EUR",
    "invoiceAmount"      :  "32.12",
    "amountPaid"      :  "32.21",
    "invoiceDate"      :  "2020-06-30"
               }]
}   

// Класс построителя полезной нагрузки:

public ReconciliationRecord createRandomReconPaymentArray(int reconArraySize) throws JsonProcessingException {

        PaymentRecon obj = new PaymentBuilderRecon()
                .withInvoiceNumber("1111")
                .withSupplierEmail("abc@test.com")
                .withPurchaseOrderNumber("12345")
                .withAccountNumber("12345")
                .withCurrency("333")
                .withInvoiceAmount(123)
                .withInvoiceDate(formatDate(2018, 11, 12))
                .withAmountPaid("200")
                .build();
        List<PaymentRecon> eachReconPayment= new ArrayList<>();


        for (int i=0; i<reconArraySize; i++) {
            eachReconPayment.add(obj);
        }
                return new ReconciliationRecordBuilder()
                .withPaymentId("123456")
                 .withReconciliationRecordInvoices(eachReconPayment).build();

---------------------------------------------------------------------------------

//ReconciliationRecordBuilder class is something like this
 @JsonInclude(value = JsonInclude.Include.NON_NULL)
    public class ReconciliationRecordBuilder {
        private String paymentId;
        private List <PaymentRecon> reconciliationRecordInvoices;


    public ReconciliationRecordBuilder withPaymentId(String paymentId) {
        this.paymentId = paymentId;
        return this;
    }

    public ReconciliationRecordBuilder withReconciliationRecordInvoices(List<PaymentRecon> reconciliationRecordInvoices) {
        this.reconciliationRecordInvoices = reconciliationRecordInvoices;
        return  this;
    }
        public ReconciliationRecord build(){
            ReconciliationRecord recon = new ReconciliationRecord();
            recon.setPaymentId(paymentId);
            recon.setReconciliationRecordInvoices(reconciliationRecordInvoices);
            return recon;



Validation in main class:

createRequest.getReconciliationRecordInvoices (). Get (0) .setSupplierEmail ("gurpreeeeeeeeeeet@test.com ");

// in the above line i want to set the supplied email address to only first list element at 0 index but when i run the code it sets the supplied email to all the indexes of list (supplier email field) and creates the below request:

{" paymentId ":" 787298 "," reconciliationRecordInvoices ": [{" invoiceNumber ":" 1003 "," supplierEmail ":" gurpreeeeeeeeeeet@test.com "," PurchaseOrderNumber ": «PO102», «accountNumber»: «ACC123», «currency»: «EUR», «invoiceAmount»: «35.12», «invoiceDate»: «2020-07-01», «amountPaid»: «34.21»,

           },
{
 "invoiceNumber"      :  "1004",
"supplierEmail"      :  "gurpreeeeeeeeeeet@test.com",
"purchaseOrderNumber"  :  "PO103",
"accountNumber"      :  "ACC143",
"currency"        :  "EUR",
"invoiceAmount"      :  "32.12",
"amountPaid"      :  "32.21",
"invoiceDate"      :  "2020-06-30"
           }]

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...