diff --git a/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java b/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java index 9ce224cf..cede1a5a 100644 --- a/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java +++ b/app/src/main/java/com/etesync/syncadapter/model/JournalModel.java @@ -88,7 +88,8 @@ public class JournalModel { @Column(length = 64, unique = true, nullable = false) String uid; - String content; + @Convert(SyncEntryConverter.class) + SyncEntry content; @Index("journal_index") @ForeignKey(update = ReferentialAction.CASCADE) @@ -96,7 +97,7 @@ public class JournalModel { Journal journal; } - public static class CollectionInfoConverter implements Converter { + static class CollectionInfoConverter implements Converter { @Override public Class getMappedType() { return CollectionInfo.class; @@ -122,4 +123,32 @@ public class JournalModel { return value == null ? null : CollectionInfo.fromJson(value); } } + + + static class SyncEntryConverter implements Converter { + @Override + public Class getMappedType() { + return SyncEntry.class; + } + + @Override + public Class getPersistedType() { + return String.class; + } + + @Override + public Integer getPersistedSize() { + return null; + } + + @Override + public String convertToPersisted(SyncEntry value) { + return value == null ? null : value.toJson(); + } + + @Override + public SyncEntry convertToMapped(Class type, String value) { + return value == null ? null : SyncEntry.fromJson(value); + } + } } diff --git a/app/src/main/java/com/etesync/syncadapter/model/SyncEntry.java b/app/src/main/java/com/etesync/syncadapter/model/SyncEntry.java index 6afd715f..98368f96 100644 --- a/app/src/main/java/com/etesync/syncadapter/model/SyncEntry.java +++ b/app/src/main/java/com/etesync/syncadapter/model/SyncEntry.java @@ -42,7 +42,11 @@ public class SyncEntry { } public static SyncEntry fromJournalEntry(String keyBase64, JournalEntryManager.Entry entry) { - return GsonHelper.gson.fromJson(entry.getContent(keyBase64), SyncEntry.class); + return fromJson(entry.getContent(keyBase64)); + } + + static SyncEntry fromJson(String json) { + return GsonHelper.gson.fromJson(json, SyncEntry.class); } public String toJson() { diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.java b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.java index 8850869a..f7cfac78 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.java +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.java @@ -231,7 +231,7 @@ abstract public class SyncManager { private void persistSyncEntry(String uid, SyncEntry syncEntry) { EntryEntity entry = new EntryEntity(); entry.setUid(uid); - entry.setContent(syncEntry.toJson()); + entry.setContent(syncEntry); entry.setJournal(getJournalEntity()); data.insert(entry); }