首页 > 代码库 > ObjectMapper
ObjectMapper
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;
}
}
ObjectMapper