Cannot construct instance ,non-static inner classes like this can only by instantiated using default

调用第三方接口返回的数据为:

{"depts":[{"mc":"B超室","bm":"20223"},{"mc":"儿科","bm":"004"}],"resultcode":0,"resulttext":"调用成功"}

实体类:

@Data
public class QueryResponse extends ResponseDTO {
    private List<Dept> depts;

    @Data
    public class Dept {
        public Dept(){}
        private String bm;
        private String mc;
    }
}

报错信息:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `***$Dept`: non-static inner classes like this can only by instantiated using default, no-argument constructor

解决方式:将Dept单独新建一个实体类(我采用的),或者使用static修饰Dept内部类。

你可能感兴趣的:(JAVA,json,java)