Question about inheritance and parameters ```impor...
# getting-started
c
Question about inheritance and parameters
Copy code
import kotlinx.serialization.Serializable

@Serializable
abstract class TagsDto( val id: String?, val name: String, val icon: String?, val color: String? )

@Serializable
class LocationTagsDto( id: String? = null, name: String, icon: String?, color: String? )
    : TagsDto( id = id, name = name, icon = icon, color = color)
This fails compilation on the second
@Serializable
This class is not serializable automatically because it has primary constructor parameters that are not properties
I don’t want to have
LocationTagsDto
add any new property to
TagsDto
. How can I make this work? Thanks in advance.
h
One option "without" a super constructor:
Copy code
import kotlinx.serialization.Serializable

@Serializable
abstract class TagsDto {
    abstract val id: String?
    abstract val name: String
    abstract val icon: String?
    abstract val color: String?
}

@Serializable
data class LocationTagsDto(
    override val id: String? = null, 
    override val name: String, 
    override val icon: String?, 
    override val color: String? 
) : TagsDto()
c
Thank you, didn’t know about the override keyword