当前位置: 首页 > 工具软件 > ObjectMapper > 使用案例 >

ObjectMapper

龚昊然
2023-12-01

    String jsonStr="";

    String content=jsonStr;

    ObjectMapper objectMapper = new ObjectMapper();
            objectMapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
            JavaType javaType = objectMapper.getTypeFactory().constructParametricType(SearchResult.class,SearchProduct.class);
            SearchResult<SearchProduct> searchResult = objectMapper.readValue(content, javaType);
            List<ProductView> datas = new ArrayList<ProductView>();
            for(SearchProduct product:searchResult.getResultList()){

     }

 

public class SearchResult<T> {
    private int totalItem;
    private List<T> resultList;
    public int getTotalItem() {
        return totalItem;
    }
    public void setTotalItem(int totalItem) {
        this.totalItem = totalItem;
    }
    public List<T> getResultList() {
        return resultList;
    }
    public void setResultList(List<T> resultList) {
        this.resultList = resultList;
    }
    
}

转载于:https://www.cnblogs.com/yqlwl66/p/4111041.html

 类似资料: