can only instantiate non-static inner class by using default, no-argument constructor

写了一个新的接口,在用POSTMAN工具调试本地接口的时候,接口报错:

org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot construct instance of `com.ncic.eam.component.dto.mobileapproval.other.MobileApprovalDoUpdateParameter$Data` (although at least one Creator exists): can only instantiate non-static inner class by using default, no-argument constructor; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.ncic.eam.component.dto.mobileapproval.other.MobileApprovalDoUpdateParameter$Data` (although at least one Creator exists): can only instantiate non-static inner class by using default, no-argument constructor\n at [Source: (PushbackInputStream); line: 6, column: 13] (through reference chain: com.ncic.eam.component.dto.mobileapproval.other.MobileApprovalDoUpdateParameter[\"data\"]->java.util.ArrayList[0])

原因是自己定义的入参比较复杂,所以使用了内部类方式接收

public class MobileApprovalDoUpdateParameter extends MobileApprovalBaseParameter implements Serializable {


	public String id;


	
	public String userCode;

	/**
	 * “EDIT_FORM”审批域内数据,取出不可编辑项,保留修改域结构。
	 */
	public List<Data> data;

	// get  set 方法
	//....


	public class Data {
		public String id;
		public String label;
		public String type;
		public List<Item> items;

		
		//set get  方法......
		//.......

问题本质为:内部非静态类无法实例化

你需要做两件事:
1、给内部类前面加上static
2、给内部类加上默认构造函数

public class MobileApprovalDoUpdateParameter extends MobileApprovalBaseParameter implements Serializable {
	public String id;
	public String userCode;
	public List<Data> data;
	public MobileApprovalDoUpdateParameter(){
	}

	// get  set 方法
	//....

	public static class Data {
		public String id;
		public String label;
		public String type;
		public List<Item> items;
		public Data(){
		}
		// get  set 方法
		//....

你可能感兴趣的:(Json,Jackson解析嵌套问题,Jackson解析内部类,Jackson解析参数报错)