Back to project page no-cloud-share.
The source code is released under:
GNU General Public License
If you think the Android project no-cloud-share 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 de.ub0r.android.nocloudshare.model; //from w w w .j a va 2 s . c o m import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import android.net.Uri; import java.lang.reflect.Type; /** * @author flx */ public class GsonFactory { private static class UriTypeAdapter implements JsonSerializer<Uri>, JsonDeserializer<Uri> { @Override public Uri deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { return Uri.parse(jsonElement.getAsString()); } @Override public JsonElement serialize(final Uri uri, final Type type, JsonSerializationContext jsonSerializationContext) { return new JsonPrimitive(uri.toString()); } } public static Gson getInstance() { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(Uri.class, new UriTypeAdapter()); return builder.create(); } }