Android Open Source - no-cloud-share Gson Factory






From Project

Back to project page no-cloud-share.

License

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.

Java Source Code

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();
    }
}




Java Source Code List

de.ub0r.android.nocloudshare.AboutActivity.java
de.ub0r.android.nocloudshare.HttpService.java
de.ub0r.android.nocloudshare.IntroActivity.java
de.ub0r.android.nocloudshare.SettingsActivity.java
de.ub0r.android.nocloudshare.ShareActivity.java
de.ub0r.android.nocloudshare.ShareFragment.java
de.ub0r.android.nocloudshare.ShareListActivity.java
de.ub0r.android.nocloudshare.http.BitmapLruCache.java
de.ub0r.android.nocloudshare.http.Httpd.java
de.ub0r.android.nocloudshare.model.GsonFactory.java
de.ub0r.android.nocloudshare.model.ShareItemContainer.java
de.ub0r.android.nocloudshare.model.ShareItem.java
de.ub0r.android.nocloudshare.views.CheckableRelativeLayout.java
de.ub0r.android.nocloudshare.views.MeasuringRelativeLayout.java
fi.iki.elonen.NanoHTTPD.java