5

I have an error :

This is not support directly by 'Parcelize', Annotate the parameter type with @RawValue if you want it to be serialized using 'writeValue'

when I implemented @Parcelize

@Parcelize data class PersonUiModel (
    var personNo: String? = null,
    var personItemNo: String? = null,
    var packageId: String? = null,
    var userInfo: UserDetailUiModel? = null,
    var personInfo: PersonDetailUiModel? = null
) : Parcelable, Cloneable {

  override public fun clone(): PersonUiModel {
    return PersonUiModel(personNo= this.personNo, personItemNo = this.personItemNo,packageId = this.packageId, userInfo = this.userInfo, personInfo = this.personInfo)
  }
}

Thanks before..

yoppie97
  • 177
  • 4
  • 18

4 Answers4

8

Make UserDetailUiModel and PersonDetailUiModel Parcelable as well (using @Parcelize or not).

Or make them Serializable and use userInfo: @RawValue UserDetailUiModel as suggested by the message, but this is a worse alternative.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
3

Add annotation @Parcelize and extends into Parcelable

@Parcelize
data class PersonUiModel (
    var personNo: String? = null,
    var personItemNo: String? = null,
    var packageId: String? = null,
    var userInfo: UserDetailUiModel? = null,
    var personInfo: PersonDetailUiModel? = null
) : Parcelable
1
  1. Install Parcelable plugin for Kotlin from Preferences-> plugins
  2. Extend your class from Parcelable
  3. Right click on the name of your class and choose: Generate -> Parcelable

It will generate all needed methods.

Elmira Frhn
  • 320
  • 4
  • 14
1

If you really want to Use @Parcable Annotation then you have to Set Your Kotlin version and Make Gradle as given below. then you able to use @Parcable annotation...

Example

@Parcelize
data class Student(val id: String, val name: String, val grade: String) : Parcelable

-----Kotlin-------- Prerequisites: Kotlin version 1.1.4 or newer

-------Gradle-----

builde.gradle


androidExtensions {
    experimental = true
}

My Gradle File.....See as Example-------->

   android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "xxx.xxx.xxx"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    androidExtensions {
        experimental = true
    }
}
Zafar Hussain
  • 264
  • 2
  • 10