springboot使用json形式传数据时,发生错误com.fasterxml.jackson.databind.exc.InvalidDefinitionException

json形式传参数,出现nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of com.zte.myproject1.entity.Account

springboot使用json形式传数据时,发生错误com.fasterxml.jackson.databind.exc.InvalidDefinitionException_第1张图片

根据错误提示发现是pojo类缺少无参数的构造函数导致

错误的pojo类:

package com.zte.myproject1.entity;

public class Account {
    int id;
    String name;
    double money;
    
    public Account(int id, String name, double money) {
        this.id = id;
        this.name = name;
        this.money = money;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }
}

正确的pojo类:

package com.zte.myproject1.entity;

public class Account {
    int id;
    String name;
    double money;

    public Account() {

    }

    public Account(int id, String name, double money) {
        this.id = id;
        this.name = name;
        this.money = money;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }
}

你可能感兴趣的:(springboot)