0

I'm trying to neglecting getter and setter in kotlin using @Parcelize. But little bit confused, here.

class College : Parcelable {
var studentFound = true
    set(value) {
        field = value
        studentFoundEvents.onNext(value)
    }
val studentFoundEvents = PublishSubject.create<Boolean>()

var sNumber: String? = null
var sLevel: String? = null

var course: Course? = null
    set(value) {
        field = value
        cName = null
        cId = null
        cProf = null  
    }
}

and i have respective constructor(source: Parcel) {}, override fun writeToParcel(dest: Parcel?, flags: Int) {} and override fun describeContents(): Int = hashCode().

I want to do convert whole Parcelable to @Parcelize. Here is what i tried, but did not workout.

@Parcelize
data class College(
    var studentFound = true,
    val studentFoundEvents = PublishSubject.create<Boolean>(), // does not work here
    var sNumber: String? = null,
    var sLevel: String? = null,
    var course: Course? = null
) : Parcelable

Is there is anything missing here? Thanks in Advance.

Horrorgoogle
  • 7,858
  • 11
  • 48
  • 81

1 Answers1

-1

I figure out couple of hour research about @Parcelize, Don't know this is best approach or not. Always highly recommend anyone, if you have any best solution.

@Parcelize
class College : Parcelable {
var studentFound = true
    set(value) {
        field = value
        studentFoundEvents.onNext(value)
    }
val studentFoundEvents = PublishSubject.create<Boolean>()

var sNumber: String? = null
var sLevel: String? = null

var course: Course? = null
    set(value) {
        field = value
        cName = null
        cId = null
        cProf = null  
    }
}

Adding @Parcelize but not moving properties to the constructor and by removing theses

constructor(source: Parcel) {}, 
override fun writeToParcel(dest: Parcel?, flags: Int) {} and 
override fun describeContents(): Int = hashCode().

Hope this will help anyone and best approaches are welcome too.

Horrorgoogle
  • 7,858
  • 11
  • 48
  • 81
  • this gives the warning: Property would not be serialized into a 'Parcel'. Add '@IgnoredOnParcel' annotation to remove the warning. So it doesn't work. – Jim Clermonts Nov 06 '20 at 12:31