剛需,jackjsonjson轉化內部類問題

lonecloud發表於2018-03-03

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;
        }
    }
}

 

相關文章