From 675bcd3927d7188209a17487fa34e807b7905ae8 Mon Sep 17 00:00:00 2001 From: abhishek818 Date: Sat, 18 Jan 2025 18:34:27 +0530 Subject: [PATCH] serialize payment account payload to comma delimited string --- .../haveno/core/payment/PaymentAccount.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/haveno/core/payment/PaymentAccount.java b/core/src/main/java/haveno/core/payment/PaymentAccount.java index 8dda8fdedd..06bcff9012 100644 --- a/core/src/main/java/haveno/core/payment/PaymentAccount.java +++ b/core/src/main/java/haveno/core/payment/PaymentAccount.java @@ -342,7 +342,22 @@ public void revertChanges() { public String toJson() { Map jsonMap = new HashMap(); - if (paymentAccountPayload != null) jsonMap.putAll(gsonBuilder.create().fromJson(paymentAccountPayload.toJson(), (Type) Object.class)); + + if (paymentAccountPayload != null) { + Map payloadMap = gsonBuilder.create().fromJson(paymentAccountPayload.toJson(), (Type) Object.class); + for (Map.Entry entry : payloadMap.entrySet()) { + Object value = entry.getValue(); + if (value instanceof List) { + String commaDelimitedString = ((List) value).stream() + .map(Object::toString) + .collect(Collectors.joining(",")); + jsonMap.put(entry.getKey(), commaDelimitedString); + } else { + jsonMap.put(entry.getKey(), value); + } + } + } + jsonMap.put("accountName", getAccountName()); jsonMap.put("accountId", getId()); if (paymentAccountPayload != null) jsonMap.put("salt", getSaltAsHex()); @@ -388,12 +403,7 @@ public PaymentAccountForm toForm() { PaymentAccountForm form = new PaymentAccountForm(PaymentAccountForm.FormId.valueOf(paymentMethod.getId())); for (PaymentAccountFormField.FieldId fieldId : getInputFieldIds()) { PaymentAccountFormField field = getEmptyFormField(fieldId); - Object value = jsonMap.get(HavenoUtils.toCamelCase(field.getId().toString())); - if (value instanceof List) { // TODO: list should already be serialized to comma delimited string in PaymentAccount.toJson() (PaymentAccountTypeAdapter?) - field.setValue(String.join(",", (List) value)); - } else { - field.setValue((String) value); - } + field.setValue((String) jsonMap.get(HavenoUtils.toCamelCase(field.getId().toString()))); form.getFields().add(field); } return form;