I have a random object and I need to parse Map<String, String>
public class ExternalIncome {
private Long operationId;
private OffsetDateTime operationDate;
private String operationCode;
private String documentNumber;
private OffsetDateTime documentDate;
private String correspondentInn;
private String correspondentName;
private String correspondentAccount;
}
I've just created it this way, but I think it's not quite elegant, rather ugly. Also, I need to intercept every iterate of the parsing to hold dynamic fields into Map<String, String> inside of the object.
public static ExternalIncome create(Map<String, String> fields) {
ExternalIncome externalIncome = new ExternalIncome();
fields.forEach((k, v) -> {
switch (k) {
case "OPER_ID":
externalIncome.setOperationId(nullableLong(v));
break;
case "OPER_DATE":
externalIncome.setOperationDate(Utils.toOffsetDateTime(v));
break;
etc
Could you help me to find the best way?