Created
August 20, 2015 11:40
-
-
Save logcat/3399e60132c1f2f9c261 to your computer and use it in GitHub Desktop.
Android Uri adapter for gson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.net.Uri; | |
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 java.lang.reflect.Type; | |
class UriAdapter implements JsonSerializer<Uri>, JsonDeserializer<Uri> { | |
@Override | |
public Uri deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { | |
return Uri.parse(json.getAsString()); | |
} | |
@Override | |
public JsonElement serialize(Uri src, Type typeOfSrc, JsonSerializationContext context) { | |
return new JsonPrimitive(src.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use dear.. please tell me?