0

I am creating spring web application and trying to add new Entity with Money data(javamoney.moneta). Here is code:

@Column(name = FLD_MONEY, unique = false, nullable = true)
private FastMoney money;

private String currencyUnit;
 
public AbstractClient() {
}

public AbstractClient(String clientId, String name, String email, String password, String roles, BigDecimal money, String currencyUnit) {
    this.currencyUnit=currencyUnit;
    this.clientId = clientId;
    this.name = name;
    this.money=FastMoney.of(money, Monetary.getCurrency(this.currencyUnit));
    this.email = email;
    this.password = hashPassword(password);
    this.active=true;
    this.roles=roles;
}

Added to table a column money and data will be filled with FastMoney. FastMoney is creating inside of constructor from BigDecimal money and String currencyUnit.

When I try to save with API endpoint with json body I have this issue:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
Cannot construct instance of org.javamoney.moneta.FastMoney(no Creators, like default constructor, exist): no int/Int-argument constructor/factory method to deserialize from Number value (32)


Here is JSON:

```json
{
   
    "money": 32,
    "currencyUnit": "EUR",
    "clientId": "Berik7182",
    "name": "Berik",
    "email": "[email protected]",
    "password": "Berik123",
    "active": true,
    "roles": "ROLE_USER",
    "location": "Pecs",
    "pwcons": 30.0
    
}

What should I do?

2
  • FastMoney does have an empty constructor too? It's possible to pass FastMoney to the AbstractClient constructor? Commented Jul 16, 2020 at 8:16
  • @Josemy Thanks for comment, FastMoney doesn't have an empty constructor , I can't change file (read-only) and what do you mean with possible to pass? Commented Jul 16, 2020 at 9:07

1 Answer 1

0

I did mistake, when I wrote money in JSON I wanted to put integer but system thought I am writing FastMoney. So I just created another int and changed name.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.