无法使用杰克逊创建内部 class 列表

Not possible to create List of inner class with jackson

是否无法创建一个包含 class 和 Jackson 的列表?外部 class Tradables 将完美运行。但是内部 class 基础将不起作用(当然,如果我将 Tradables 设为内部 class)。

有没有办法解决这个问题,而不是让属于 json 对象数组的每个 class 都在它自己的 class 中?

此外,JsonProperty 是否在 set 方法之上也没有关系。任何不属于数组的内部 class 也可以工作。

private String sector_group;

    @JsonProperty("underlyings")
    private List<Underlyings> listUnderlyings;
    @JsonProperty("tradables")
    private List<Tradables> listTradables;


    public class Underlyings {
        private long instrument_id;
        private String symbol;
        private String isin_code;
        public long getInstrument_id() {
            return instrument_id;
        }
        public void setInstrument_id(long instrument_id) {
            this.instrument_id = instrument_id;
        }
        public String getSymbol() {
            return symbol;
        }
        public void setSymbol(String symbol) {
            this.symbol = symbol;
        }
        public String getIsin_code() {
            return isin_code;
        }
        public void setIsin_code(String isin_code) {
            this.isin_code = isin_code;
        }

    }

映射方法

ObjectMapper mapper = new ObjectMapper();

        try {
            String json = RestLogin.getBaseResource()
                    .path("instruments").path("lookup").path("market_id_identifier").path(market_id + ":" + identifier)
                    .request(RestLogin.getResponsetype()).get(String.class);

            List<Instrument> tmpInstruments = mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, Instrument.class));

Jackson and Inner Classes: yes, you can use, but they must be STATIC inner classes

这是一个片段(但您应该阅读整篇文章以获得更多解释)。

If you do not add static, resulting class is generally useless for Jackson as well as any other data binding framework (Hibernate, JAXB); can often be serialized, but never serialized into