package com.iamberry.app.tool.util;

import java.util.Collection;
import java.util.List;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iamberry.app.tool.dto.AddressDTO;

/** 
 * @author North 
 * @date 2016年3月1日 上午11:32:06 
 * @version V1.0
 */
public class JsonParseUtil {

	static ObjectMapper om = new ObjectMapper();

	public static Object parseObject(String json, Class<?> clz) {
		try {
			return om.readValue(json, clz);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static Collection<?> parseList(String json, TypeReference<?> reference) {
		try {
			return om.readValue(json, reference);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static Object parseAddress(String json) {
		try {
			return om.readValue(json, AddressDTO.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	

	public static List<AddressDTO> parseAddressList(String json) {
		try {
			return om.readValue(json, new TypeReference<List<AddressDTO>>() {
			});
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
