// Path: library/src/main/java/com/thefinestartist/royal/util/DateUtil.java
// public class DateUtil {
// 
//     public static String DATE_FORMAT = "MMM d, yyyy h:mm:ss aa"; // Aug 6, 2015 1:23:33 AM
//     private static SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.US);
// 
//     private DateUtil() {
//     }
// 
//     public static String getDateFormat(Date date) {
//         if (date == null)
//             return null;
//         return dateFormat.format(date);
//     }
// }
// 
// Path: library/src/main/java/io/realm/RoyalAccess.java
// public class RoyalAccess {
// 
//     public static Realm getRealm(@NonNull RealmObject object) {
//         return object.realm;
//     }
// 
//     public static Row getRow(@NonNull RealmObject object) {
//         return object.row;
//     }
// 
//     public static Table getTable(@NonNull RealmObject object) {
//         return object.row == null ? null : object.row.getTable();
//     }
// 
//     public static boolean isProxy(@NonNull RealmObject object) {
//         return object instanceof RealmObjectProxy;
//     }
// 
//     public static boolean hasPrimaryKey(@NonNull Realm realm, @NonNull RealmObject object) {
//         return realm.getTable(object.getClass()).hasPrimaryKey();
//     }
// 
//     public static Class<? extends RealmObject> getClass(@NonNull Realm realm, @NonNull Table table) {
//         List<Class<? extends RealmObject>> classes = realm.getConfiguration().getSchemaMediator().getModelClasses();
//         for (Class<? extends RealmObject> clazz : classes)
//             if (realm.getTable(clazz).getName().equals(table.getName()))
//                 return clazz;
// 
//         return null;
//     }
// 
//     public static RealmObject get(@NonNull Realm realm, @NonNull Table table, long rowIndex) {
//         if (rowIndex < 0)
//             return null;
// 
//         UncheckedRow row = table.getUncheckedRow(rowIndex);
//         RealmObject result = realm.getConfiguration().getSchemaMediator().newInstance(getClass(realm, table));
//         result.row = row;
//         result.realm = realm;
//         return result;
//     }
// 
//     // TODO: Free RealmObject from Realm
// 
// 
//     // TODO: Clone RealmObject without Realm information
//     // TODO: Problem #1 Serializing RealmObject has same speed of just committing it using Realm
// 
// }


import android.support.annotation.NonNull;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.thefinestartist.royal.util.DateUtil;
import java.util.Arrays;
import java.util.Date;
import io.realm.Realm;
import io.realm.RealmObject;
import io.realm.RoyalAccess;
import io.realm.internal.ColumnType;
import io.realm.internal.LinkView;
import io.realm.internal.Row;
import io.realm.internal.Table;
package com.thefinestartist.royal;





/**
 * Created by TheFinestArtist on 7/8/15.
 */
public class Rson {

    private static final Object lock = new Object();
    private static Gson gson;

    public static Gson getGson() {
        synchronized (lock) {
            if (gson != null)
                return gson;
            gson = new GsonBuilder()
                    .setExclusionStrategies(new ExclusionStrategy() {
                        @Override
                        public boolean shouldSkipField(FieldAttributes f) {
                            return f.getDeclaringClass().equals(RealmObject.class);
                        }

                        @Override
                        public boolean shouldSkipClass(Class<?> clazz) {
                            return false;
                        }
                    })
                    .create();
            return gson;
        }
    }

    public static String toJsonString(@NonNull RealmObject object) {
        return toJsonString(object, 1);
    }

    @SuppressWarnings("ConstantConditions")
    public static String toJsonString(@NonNull RealmObject object, int depth) {
// Path: library/src/main/java/com/thefinestartist/royal/util/DateUtil.java
// public class DateUtil {
// 
//     public static String DATE_FORMAT = "MMM d, yyyy h:mm:ss aa"; // Aug 6, 2015 1:23:33 AM
//     private static SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.US);
// 
//     private DateUtil() {
//     }
// 
//     public static String getDateFormat(Date date) {
//         if (date == null)
//             return null;
//         return dateFormat.format(date);
//     }
// }
// 
// Path: library/src/main/java/io/realm/RoyalAccess.java
// public class RoyalAccess {
// 
//     public static Realm getRealm(@NonNull RealmObject object) {
//         return object.realm;
//     }
// 
//     public static Row getRow(@NonNull RealmObject object) {
//         return object.row;
//     }
// 
//     public static Table getTable(@NonNull RealmObject object) {
//         return object.row == null ? null : object.row.getTable();
//     }
// 
//     public static boolean isProxy(@NonNull RealmObject object) {
//         return object instanceof RealmObjectProxy;
//     }
// 
//     public static boolean hasPrimaryKey(@NonNull Realm realm, @NonNull RealmObject object) {
//         return realm.getTable(object.getClass()).hasPrimaryKey();
//     }
// 
//     public static Class<? extends RealmObject> getClass(@NonNull Realm realm, @NonNull Table table) {
//         List<Class<? extends RealmObject>> classes = realm.getConfiguration().getSchemaMediator().getModelClasses();
//         for (Class<? extends RealmObject> clazz : classes)
//             if (realm.getTable(clazz).getName().equals(table.getName()))
//                 return clazz;
// 
//         return null;
//     }
// 
//     public static RealmObject get(@NonNull Realm realm, @NonNull Table table, long rowIndex) {
//         if (rowIndex < 0)
//             return null;
// 
//         UncheckedRow row = table.getUncheckedRow(rowIndex);
//         RealmObject result = realm.getConfiguration().getSchemaMediator().newInstance(getClass(realm, table));
//         result.row = row;
//         result.realm = realm;
//         return result;
//     }
// 
//     // TODO: Free RealmObject from Realm
// 
// 
//     // TODO: Clone RealmObject without Realm information
//     // TODO: Problem #1 Serializing RealmObject has same speed of just committing it using Realm
// 
// }


// Path: library/src/main/java/com/thefinestartist/royal/Rson.java
import android.support.annotation.NonNull;
import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.thefinestartist.royal.util.DateUtil;
import java.util.Arrays;
import java.util.Date;
import io.realm.Realm;
import io.realm.RealmObject;
import io.realm.RoyalAccess;
import io.realm.internal.ColumnType;
import io.realm.internal.LinkView;
import io.realm.internal.Row;
import io.realm.internal.Table;

package com.thefinestartist.royal;





/**
 * Created by TheFinestArtist on 7/8/15.
 */
public class Rson {

    private static final Object lock = new Object();
    private static Gson gson;

    public static Gson getGson() {
        synchronized (lock) {
            if (gson != null)
                return gson;
            gson = new GsonBuilder()
                    .setExclusionStrategies(new ExclusionStrategy() {
                        @Override
                        public boolean shouldSkipField(FieldAttributes f) {
                            return f.getDeclaringClass().equals(RealmObject.class);
                        }

                        @Override
                        public boolean shouldSkipClass(Class<?> clazz) {
                            return false;
                        }
                    })
                    .create();
            return gson;
        }
    }

    public static String toJsonString(@NonNull RealmObject object) {
        return toJsonString(object, 1);
    }

    @SuppressWarnings("ConstantConditions")
    public static String toJsonString(@NonNull RealmObject object, int depth) {
        if (!RoyalAccess.isProxy(object)) {