TheElectronWill / night-config

Powerful java configuration library for toml, yaml, hocon, json and in-memory configurations. Serialization/deserialization framework.
GNU Lesser General Public License v3.0
243 stars 28 forks source link

How use serialization on this example #134

Closed mani1232 closed 1 year ago

mani1232 commented 1 year ago

I don't know why it doesn't work

{
  "type": "StatementItem",
  "data": {
    "account": "10000000",
    "statementItem": {
      "id": "4256562345",
      "time": 1675262031,
      "description": "fghfgjfghjghj",
      "mcc": 4829,
      "originalMcc": 4829,
      "amount": 500,
      "operationAmount": 500,
      "currencyCode": 980,
      "commissionRate": 0,
      "cashbackAmount": 0,
      "balance": 10620,
      "hold": true
    }
  }
}

My example on java

public class Payment {

  String type;
  Data data;

  public String getType() {
    return type;
  }

  public Data getData() {
    return data;
  }

  public static class Data {

    StatementItem statementItem;
    String account;

    public StatementItem getStatementItem() {
      return statementItem;
    }

    public String getAccount() {
      return account;
    }

    public static class StatementItem {

      int amount;
      int commissionRate;

      int balance;
      int operationAmount;

      int cashbackAmount;

      String description;

      int originalMcc;

      String id;

      Long time;

      int mcc;

      int currencyCode;

      boolean hold;

      public int getAmount() {
        return amount;
      }

      public int getBalance() {
        return balance;
      }
    }
  }
}
TheElectronWill commented 1 year ago

What do you mean by

it doesn't work

?

Do you get an error of some kind? How are you (de)serializing?

mani1232 commented 1 year ago

What do you mean by

it doesn't work

?

Do you get an error of some kind? How are you (de)serializing?

No errors, just empty values

UnmodifiableConfig config = JsonFormat.fancyInstance().createParser().parse(exchange.getRequestBody(), StandardCharsets.UTF_8);
Payment payment = new ObjectConverter().toObject(config, Payment::new);
System.out.println(payment.getType()); // work fine
System.out.println(String.valueOf(payment.getData().getAccount())); // dont work
mani1232 commented 1 year ago

And for some reason symbols are used instead of Ukrainian words

Example: ╧хЁхърч эр ърЁЄъє

TheElectronWill commented 1 year ago

Hello! Do you still happen to have this problem? It looks like the encoding may be wrong somewhere.

mani1232 commented 1 year ago

Hello! Do you still happen to have this problem? It looks like the encoding may be wrong somewhere.

I fixed the encoding problem, but the above is not