Back to project page Buddy-Android-SDK.
The source code is released under:
Apache License
If you think the Android project Buddy-Android-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.buddy.sdk; /*from w w w.ja v a 2 s . co m*/ import com.google.gson.Gson; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import java.lang.reflect.Type; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; class BuddyDateDeserializer implements JsonDeserializer<Date> { private Class clazz; private final static Pattern pattern = Pattern.compile("/Date\\((-?\\d+)\\)/"); public static Date deserialize(String str) { Matcher m = pattern.matcher(str); if (m.find()) { Long unixDate = Long.decode(m.group(1)); return new Date(unixDate); } return null; } @Override public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext ctx) throws JsonParseException { String str = json.getAsString(); return deserialize(str); } }