// Path: library/src/main/java/com/alexvasilkov/android/commons/utils/GsonHelper.java
// @SuppressWarnings("unused") // Public API
// public class GsonHelper {
// 
//     private static Boolean hasGson;
//     private static Object gson;
// 
//     public static boolean hasGson() {
//         if (hasGson == null) {
//             try {
//                 Class.forName("com.google.gson.Gson");
//                 hasGson = true;
//             } catch (Exception e) {
//                 hasGson = false;
//             }
//         }
//         return hasGson;
//     }
// 
//     public static Gson get() {
//         if (gson == null) {
//             gson = new Gson();
//         }
//         return (Gson) gson;
//     }
// 
//     public static String toJson(Object obj) {
//         try {
//             return obj == null ? null : get().toJson(obj);
//         } catch (Exception e) {
//             Log.e("GsonHelper", "Cannot convert object to JSON", e);
//             return null;
//         }
//     }
// 
//     public static <T> T fromJson(String str, Class<T> clazz) {
//         return fromJson(str, (Type) clazz);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static <T> T fromJson(String str, Type type) {
//         try {
//             return str == null ? null : (T) get().fromJson(str, type);
//         } catch (Exception e) {
//             Log.e("GsonHelper", "Cannot parse JSON to object", e);
//             return null;
//         }
//     }
// 
// }


import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Base64;
import com.alexvasilkov.android.commons.utils.GsonHelper;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.Date;
    }

    /**
     * Stores object as json encoded string.
     * Gson library should be available in classpath.
     */
    @NonNull
    public static SharedPreferences.Editor putJson(@NonNull SharedPreferences.Editor editor,
            @NonNull String key, @Nullable Object obj) {
        editor.putString(key, GsonHelper.toJson(obj));
        return editor;
    }

    /**
     * Retrieves object stored as json encoded string.
     * Gson library should be available in classpath.
     */
    @Nullable
    public static <T> T getJson(@NonNull SharedPreferences prefs,
            @NonNull String key, @NonNull Class<T> clazz) {
        return getJson(prefs, key, (Type) clazz);
    }

    /**
     * Retrieves object stored as json encoded string.
     * Gson library should be available in classpath.
     */
    @Nullable
    public static <T> T getJson(@NonNull SharedPreferences prefs,
            @NonNull String key, @NonNull Type type) {
// Path: library/src/main/java/com/alexvasilkov/android/commons/utils/GsonHelper.java
// @SuppressWarnings("unused") // Public API
// public class GsonHelper {
// 
//     private static Boolean hasGson;
//     private static Object gson;
// 
//     public static boolean hasGson() {
//         if (hasGson == null) {
//             try {
//                 Class.forName("com.google.gson.Gson");
//                 hasGson = true;
//             } catch (Exception e) {
//                 hasGson = false;
//             }
//         }
//         return hasGson;
//     }
// 
//     public static Gson get() {
//         if (gson == null) {
//             gson = new Gson();
//         }
//         return (Gson) gson;
//     }
// 
//     public static String toJson(Object obj) {
//         try {
//             return obj == null ? null : get().toJson(obj);
//         } catch (Exception e) {
//             Log.e("GsonHelper", "Cannot convert object to JSON", e);
//             return null;
//         }
//     }
// 
//     public static <T> T fromJson(String str, Class<T> clazz) {
//         return fromJson(str, (Type) clazz);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public static <T> T fromJson(String str, Type type) {
//         try {
//             return str == null ? null : (T) get().fromJson(str, type);
//         } catch (Exception e) {
//             Log.e("GsonHelper", "Cannot parse JSON to object", e);
//             return null;
//         }
//     }
// 
// }


// Path: library/src/main/java/com/alexvasilkov/android/commons/prefs/PreferencesHelper.java
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Base64;
import com.alexvasilkov.android.commons.utils.GsonHelper;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.Date;

    }

    /**
     * Stores object as json encoded string.
     * Gson library should be available in classpath.
     */
    @NonNull
    public static SharedPreferences.Editor putJson(@NonNull SharedPreferences.Editor editor,
            @NonNull String key, @Nullable Object obj) {
        editor.putString(key, GsonHelper.toJson(obj));
        return editor;
    }

    /**
     * Retrieves object stored as json encoded string.
     * Gson library should be available in classpath.
     */
    @Nullable
    public static <T> T getJson(@NonNull SharedPreferences prefs,
            @NonNull String key, @NonNull Class<T> clazz) {
        return getJson(prefs, key, (Type) clazz);
    }

    /**
     * Retrieves object stored as json encoded string.
     * Gson library should be available in classpath.
     */
    @Nullable
    public static <T> T getJson(@NonNull SharedPreferences prefs,
            @NonNull String key, @NonNull Type type) {
        return GsonHelper.fromJson(prefs.getString(key, null), type);