I have a model class in Java which I converted to data class in kotlin
public class VideoAssets implements Serializable {
@SerializedName("type")
@Expose
String type;
@SerializedName("mpeg")
@Expose
List<Mpeg> mpeg = null;
@SerializedName("hls")
@Expose
String hls;
@SerializedName("widevine")
@Expose
WideVine wideVine;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public List<Mpeg> getMpeg() {
return mpeg;
}
public void setMpeg(List<Mpeg> mpeg) {
this.mpeg = mpeg;
}
public String getHls() {
hls = Macros.INSTANCE.replaceURl(hls);
return hls;
}
public void setHls(String hls) {
this.hls = hls;
}
public WideVine getWideVine() {
return wideVine;
}
public void setWideVine(WideVine wideVine) {
this.wideVine = wideVine;
}
}
As you see I want to change the value of variable hls
when I retrieve it.
I created the data class as below
data class VideoAssets(@SerializedName("mpeg") @Expose
var mpeg: List<Mpeg> = emptyList(),
@SerializedName("hls")
@Expose
var hls: String,
@SerializedName("widevine")
@Expose
val wideVine: WideVine? = null) : Serializable
I am struggling here as how should I update the get method for data class. After searching and taking reference from Override getter for Kotlin data class I even created a non data class which doesn't seem to work
class VideoAssets(@SerializedName("mpeg") @Expose
var mpeg: List<Mpeg> = emptyList(),
@SerializedName("hls")
@Expose
val hlsUrl: String? = null,
@SerializedName("widevine")
@Expose
val wideVine: WideVine? = null) : Serializable {
val hls: String? = hlsUrl
get() = field?.let { Macros.replaceURl(it) }
}
Whenerver I try to retrieve videoAssets.getHls()
it returns null while it should return the new value. The object videoAssets.gethlsUrl()
has the value but not `videoAssets.getHls()' is always null.
Can someone point me what I am missing?