标签:des blog io ar for java on div log
自定义DateAdapter
public class DateAdapter implements JsonDeserializer<Date> {
	private final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	public Date deserialize(JsonElement arg0, Type arg1,
			JsonDeserializationContext arg2) throws JsonParseException {
		try {
			return df.parse(arg0.getAsString());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
}
然后在代码中创建转换器即可:
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new DateAdapter()).create();
标签:des blog io ar for java on div log
原文地址:http://www.cnblogs.com/fangjianbin/p/4150949.html