java报错:com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor

解决:加上static就好

参考:java - JsonMappingException: No suitable constructor found for type [simple type, class ]: can not instantiate from JSON object - Stack Overflow

示例代码:

 

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
@Data
@Accessors(chain = true)
public class QueryEniResponse {
    private String eniId;
    private String name;
    private String vpcId;
    private String subnetId;
    private String zoneName;
    private String description;
    private String createdTime;
    private String macAddress;
    private String status;
    private String networkInterfaceTrafficMode;
    private List<PrivateIpItem>  privateIpSet = new ArrayList<>();
    private List<String> securityGroupIds = new ArrayList<>();
    private List<String> enterpriseSecurityGroupIds = new ArrayList<>();

    @JsonIgnoreProperties(ignoreUnknown = true)
    @Data
    @Accessors(chain = true)
    public static class PrivateIpItem{
        private Boolean primary;
        private String privateIpAddress;
        private String publicIpAddress;
    }
}



 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐