Uploaded image for project: 'Realm Kotlin'
  1. Realm Kotlin
  2. RKOTLIN-388

Add support for `@PersistedName` annotation for fields to override underlying name

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Local
    • None

      Similar to Realm Java, we should provide the option of mapping Kotlin field names to their underlying (persisted) representation:

      class Example : RealmObject {
        @PersistedName(name = "myPersistedName")
        var myKotlinName: String = ""
      }
      

      In Realm Java, we allow for different naming strategies, overriding all names at once. This idea was pulled from GSON, but I'm not sure it is worth porting to Java as it didn't seemed to be used really.

      Other API's will also be affected by this:

      • RealmClass should return the persisted name, not the public (Kotlin) name.
      • RQL queries should support both the persisted and public names.

      TODO:

      // Step 1

      • [ ] Create PersistedName annotation in io.realm.kotlin.types.annotations
      • [ ] Modify AccessorModifierIrGeneration.modifyPropertiesAndCollectSchema to account for internal values
      • [ ] Modify RealmModelSyntheticPropertiesGeneration (see line 501, maybe other places)
      • [ ] Validate that persisted and public names are a unique set. They are not allowed to overlap. This check should happen at compile time.
      • [ ] Verify in Realm Studio that schema is modified correctly

      // Step 2

      • [ ] Make sure that RealmClass returns the mapped values, not public names in the model class.

      // Step 3

      • [ ] Modify PropertyInfo to correctly set publicName
      • [ ] Verify that queries can use both persisted and public names in queries.

            Assignee:
            gagik.amaryan@mongodb.com Gagik Amaryan
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: