1.今天在编写jackjson将json转换成object的时候,突然报错:
nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of com.ferelife.emms.vo.price.AuditCommitVo$PriceNode: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
一脸懵逼啊,不是有构造方法嘛,为啥又说我没有构造方法嘛,这不是在逗我吗?
一阵狂查后发现原来这货在进行绑定的时候是采用的静态类调用方式创建内部类实例即 Demo.new InnerDemo()创建。
则将内部类声明为public static class 类型即可解决
看下面一个例子
package com.ferelife.emms.vo.price; import com.ferelife.emms.vo.audit.AuditVo; import java.util.List; /** * @author lonecloud * @version v1.0 * @date 上午11:02 2018/3/3 */ public class AuditCommitVo extends AuditVo { private List<PriceNode> detail; public List<PriceNode> getDetail() { return detail; } public void setDetail(List<PriceNode> detail) { this.detail = detail; } public static class PriceNode { public PriceNode() { } private String commodityId; private int status; public String getCommodityId() { return commodityId; } public void setCommodityId(String commodityId) { this.commodityId = commodityId; } public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } } }