简体   繁体   中英

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of

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": "berik@gmail.com",
    "password": "Berik123",
    "active": true,
    "roles": "ROLE_USER",
    "location": "Pecs",
    "pwcons": 30.0
    
}

What should I do?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM