Skip to content

Commit

Permalink
serialize payment account payload to comma delimited string
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek818 committed Jan 18, 2025
1 parent 130a45c commit 675bcd3
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions core/src/main/java/haveno/core/payment/PaymentAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,22 @@ public void revertChanges() {

public String toJson() {
Map<String, Object> jsonMap = new HashMap<String, Object>();
if (paymentAccountPayload != null) jsonMap.putAll(gsonBuilder.create().fromJson(paymentAccountPayload.toJson(), (Type) Object.class));

if (paymentAccountPayload != null) {
Map<String, Object> payloadMap = gsonBuilder.create().fromJson(paymentAccountPayload.toJson(), (Type) Object.class);
for (Map.Entry<String, Object> 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());
Expand Down Expand Up @@ -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<String>) value));
} else {
field.setValue((String) value);
}
field.setValue((String) jsonMap.get(HavenoUtils.toCamelCase(field.getId().toString())));
form.getFields().add(field);
}
return form;
Expand Down

0 comments on commit 675bcd3

Please sign in to comment.