public static byte[] serialize(VersionedObject versionedObject, int CRCBytes)
     throws NotSerializableException {
   FragmentedByteArray data =
       new FragmentedByteArray(
           Serializer.serializeObject(versionedObject.getCurrentVersion().toArrayList()));
   Map<String, Serializable> attributes = versionedObject.serialize();
   data.add(Serializer.serialize(attributes.size()));
   for (Map.Entry<String, Serializable> entry : attributes.entrySet()) {
     byte[] attributeName = Serializer.serialize(entry.getKey());
     // find the type of the attributes
     byte[] type;
     byte[] attributeArray;
     Object attribute = entry.getValue();
     if (attribute instanceof String) {
       type = STRING_TYPE;
       attributeArray = Serializer.serialize((String) attribute);
     } else if (attribute instanceof Boolean || attribute == null) {
       // null value are serialized as a null Boolean
       type = BOOLEAN_TYPE;
       attributeArray = Serializer.serialize((Boolean) attribute);
     } else if (attribute instanceof Byte) {
       type = BYTE_TYPE;
       attributeArray = Serializer.serialize((Byte) attribute);
     } else if (attribute instanceof Short) {
       type = SHORT_TYPE;
       attributeArray = Serializer.serialize((Short) attribute);
     } else if (attribute instanceof Integer) {
       type = INTEGER_TYPE;
       attributeArray = Serializer.serialize((Integer) attribute);
     } else if (attribute instanceof Long) {
       type = LONG_TYPE;
       attributeArray = Serializer.serialize((Long) attribute);
     } else if (attribute instanceof Float) {
       type = FLOAT_TYPE;
       attributeArray = Serializer.serialize((Float) attribute);
     } else if (attribute instanceof Double) {
       type = DOUBLE_TYPE;
       attributeArray = Serializer.serialize((Double) attribute);
     } else if (attribute instanceof Enum<?>) {
       type = ENUM_TYPE;
       attributeArray =
           Serializer.addArrays(
               Serializer.serialize(attribute.getClass().getName()),
               Serializer.serialize((Enum) attribute));
     } else if (attribute instanceof byte[]) {
       type = BYTE_ARRAY_TYPE;
       attributeArray = Serializer.serialize((byte[]) attribute);
     } else {
       type = SERIALIZABLE_TYPE;
       attributeArray = Serializer.serializeObject((Serializable) attribute);
     }
     data.add(attributeName, type, attributeArray).generateArray();
   }
   return CRC.addCRC(data.generateArray(), CRCBytes, true);
 }
  void storeSyncContacts() {
    SQLiteDatabase db = handler.getWritableDatabase();
    if (db == null) {
      return;
    }
    handler.dropTable(db);

    int id = 0;
    for (SyncContact sc : syncContacts) {
      ContentValues values = new ContentValues();
      values.put(DatabaseHandler.ID_COLUMN, id);
      values.put(DatabaseHandler.CONTACT, Serializer.serializeObject(sc));

      long resRowInd = db.insert(DatabaseHandler.TABLE_NAME, null, values);
      Log.e("INSERT QUERY ID", String.valueOf(resRowInd));
      id += 1;
    }
    db.close();
  }