import java.util.HashMap;
import java.util.List; import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.type.TypeFactory;
import org.codehaus.jackson.type.JavaType; import com.leighyu.utils.Constants; public class AsyncGetProductCategories<T> implements Runnable { private final Class<T> type;
public interface OnFinishListener<T> {
public void onFinish(List<T> t);
}
private OnFinishListener<T> onFinishListener;
public void setFinishListener(OnFinishListener<T> onFinishListener) {
this.onFinishListener = onFinishListener;
} private String url;
private HashMap<String, String> params;
public AsyncGetProductCategories(Class<T> type) {
this.type = type;
this.url = Constants.URL + "productcategorylist/getalllevelone.html";
HashMap<String, String> params = new HashMap<String, String>();
params.put("testkey", "testvalue");
this.params = params;
} @Override
public void run() {
try {
String result = WebUtil.httpPostJson(this.url, this.params); ObjectMapper mapper = new ObjectMapper();
JavaType listType = TypeFactory.collectionType(List.class, type);
List<T> entities = mapper.readValue(result, listType);
if(onFinishListener != null) {
onFinishListener.onFinish(entities);
}
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
        AsyncGetProductCategories<ProductCategoryEntity> agpc =
new AsyncGetProductCategories<ProductCategoryEntity>(ProductCategoryEntity.class);
agpc.setFinishListener(new OnFinishListener<ProductCategoryEntity>(){
@Override
public void onFinish(final List<ProductCategoryEntity> entities) {
activity.runOnUiThread(new Runnable()
{
@Override
public void run() {
drawLevelOne(entities);
mProgressDialog.dismiss();
}
});
}
}); new Thread(agpc).start();

jackson 解析结合类(需要传入Class, 和 Class.Class, 回调方法是List<Class>)的更多相关文章

  1. jackson 解析json含有不规则的属性的json字符串的方法

    对于json中含有点号,等其它特殊的,不是规范的java变量名的字符,能够使用一个注解来处理. 贴代码: import com.fasterxml.jackson.annotation.JsonPro ...

  2. 爬虫代码实现五:解析所有分页url并优化解析实现类

    如图,我们进入优酷首页,可以看到电视剧列表,我们称这个页面为电视剧列表页,而点击进入某个电视剧,则称为电视剧详情页.那么如何获取所有分页以及对应的详情页呢,通过下面的分页得到. 因此,首先,我们将St ...

  3. 记一次FastJSON和Jackson解析json时遇到的中括号问题

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jadyer/article/details/24395015 完整版见https://jadyer. ...

  4. C#字符串数组排序 C#排序算法大全 C#字符串比较方法 一个.NET通用JSON解析/构建类的实现(c#) C#处理Json文件 asp.net使用Jquery+iframe传值问题

    C#字符串数组排序   //排序只带字符的数组,不带数字的 private   string[]   aa   ={ "a ", "c ", "b & ...

  5. JSON介绍及Android最全面解析方法(Gson、AS自带org.son、Jackson解析)

    前言 今天,我们来介绍一下现今主流的数据交换格式-JSON! 相同作为主流为数据交换格式-XML,假设有兴趣能够阅读我写的XML及其DOM.SAX.PULL解析方法和对照 文件夹 定义 JavaScr ...

  6. Spring5源码解析6-ConfigurationClassParser 解析配置类

    ConfigurationClassParser 在ConfigurationClassPostProcessor#processConfigBeanDefinitions方法中创建了Configur ...

  7. 解析ThreadPoolExecutor类是如何保证线程池正确运行的

    摘要:对于线程池的核心类ThreadPoolExecutor来说,有哪些重要的属性和内部类为线程池的正确运行提供重要的保障呢? 本文分享自华为云社区<[高并发]通过源码深度解析ThreadPoo ...

  8. 【高并发】深度解析ScheduledThreadPoolExecutor类的源代码

    在[高并发专题]的专栏中,我们深度分析了ThreadPoolExecutor类的源代码,而ScheduledThreadPoolExecutor类是ThreadPoolExecutor类的子类.今天我 ...

  9. 解析C#类中的构造函数

    <解析C#类中的构造函数> 一.  C#中的构造函数概述: C#中类包含数据成员和函数成员.函数成员提供了操作类中数据的某些功能,包括方法.属性.构造器和终结器.运算符和索引器. 构造函数 ...

随机推荐

  1. 从cin读入一组词并把它们存入一个vector对象,然后设法把所有词都改写为大写字母。

    #include<iostream> #include<vector> #include<string> using namespace std; int main ...

  2. 使用socket实现信用卡程序和迷你购物商城

    #-*- coding:utf-8 -*- from moudle import * import socketserver import json import os import time imp ...

  3. mysql颠覆实战笔记(七)--白话理解事务

    今天我们学习web开发级mysql颠覆实战课程第9课没MYSQL事务(一):白话理解事务.前面有两节课第7讲:商品系统设计(四):商品属性设计之自定义属性,第8讲:商品系统设计(五):一维属性的商品价 ...

  4. AspxGridView整理文档【转】

    ASPxGridView属性:概述设置(Settings) <Settings GridLines="Vertical" : 网格样式 Vertical, Both, Non ...

  5. (转载)MatLab绘图

    转载自:http://www.cnblogs.com/hxsyl/archive/2012/10/10/2718380.html 转载自:http://www.cnblogs.com/jeromebl ...

  6. uva 10152 ShellSort 龟壳排序(希尔排序?)

    今天状态总是很糟,这种题目卡了一天... 是不是休息时间太少了,头脑迟钝了... 名字叫希尔排序,我还以为跟它有关,还搜索了下资料. 只要找到trick就会发现是很水的题目.只要对比下就能找到哪些是移 ...

  7. IOS微信中看文章跳转页面后点击返回无效

    经过查找原因发现,下面两种链接,链接1返回不了,链接2可以返回. 链接1:http://mp.weixin.qq.com/s?__biz=MzA5NDY5MzcyNA==&mid=265089 ...

  8. (转).net项目技术选型总结

    原文作者:mcgrady 原文地址:.net项目技术选型总结 做.net开发已经几年了,也参与开发了很多大大小小的项目,所以现在希望总结出一套开发.net项目的常用技术,也为以后做项目技术选型的时候作 ...

  9. Linux 命令 - ss: 查看套接字统计信息

    命令格式 ss [options] [ FILTER ] 命令参数 -h, --help 显示帮助信息. -V, --version 显示版本信息. -n, --numeric 不解析服务名称. -r ...

  10. Ajax-数据格式-xml,json

    xml demo testDataXml <%@ page language="java" contentType="text/html; charset=UTF- ...