mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-03-12 09:31:15 +00:00
serialize payment account payload to comma delimited string
This commit is contained in:
parent
130a45c99a
commit
675bcd3927
1 changed files with 17 additions and 7 deletions
|
@ -342,7 +342,22 @@ public abstract class PaymentAccount implements PersistablePayload {
|
|||
|
||||
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());
|
||||
|
@ -388,12 +403,7 @@ public abstract class PaymentAccount implements PersistablePayload {
|
|||
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;
|
||||
|
|
Loading…
Reference in a new issue