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 www .j av a 2 s . co m import android.location.Location; 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 BuddyLocationDeserializer implements JsonDeserializer<Location> { private Class clazz; @Override public Location deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext ctx) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); if (jsonObj != null && jsonObj.has("lat") && jsonObj.has("lng")) { Location l = new Location("Buddy"); l.setLatitude(jsonObj.get("lat").getAsDouble()); l.setLongitude(jsonObj.get("lng").getAsDouble()); return l; } throw new JsonParseException("Invalid location: " + json.toString()); } }