In kotlinx , do I need to write serialization str...
# javascript
j
In kotlinx , do I need to write serialization strategy for each List<CustomClass> inside other class?
d
No you don't have to.
As long as
CustomClass
has been marked as
@Serializable
.
j
but when I try to accea to that List throws an exception n't locate argument-less serializer for class null. For generic classes, such as lists, please provide serializer explicitly.
d
Is this in Ktor?
j
no. kotlinx directly
d
Which kotlinx library?
j
kotlinx-serialization
d
Are you using
Json.parse("")
?
j
override   fun< T> result(clazz : KSerializer<T> ): T {
return Json.nonstrict.fromJson(clazz,statusResponse.data!!)
}
d
You'll have to pass in
CustomClass.serializer().list
.
j
where?
d
result(CustomClass.serializer().list)
?
j
is into another class @Serializable data class User( var id: Long?, var email: String?, var lastName: String?, var username: String?, var name: String?, var password: String?, var phone: String?, //var origin: String? @ContextualSerialization var registrationDate:Date? = null, val userRoles :List<Role>, @ContextualSerialization var birthday: Date?= null )
d
Oh
I'm guessing you've already marked
Role
class with
@Serializable
, so I'm not sure why this doesn't work.
Might get more help in #serialization .
j
thx