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?
FastMoney
does have an empty constructor too? It's possible to passFastMoney
to theAbstractClient
constructor? – Josemy