hey, how to serialize `List<File>` ? I was ...
# serialization
j
hey, how to serialize
List<File>
? I was able to create a
KSerializer<File>
, but how to apply that to a field that has a List of it ?
a
j
How is that going to help me? I just would like to be able to serialize a List of File...
a
Copy code
typealias FileAsString = @Serializable(MyFileSerializer::class) File

object MyFileSerializer : KSerializer<File> { 
  // ...
}

data class FooItem(
  val files: List<FileAsString>
)
does that make sense? Let me know if something needs more explanation :)
j
Ahhh, with this approach the annotation is applied to File even though I am declaring a List. That would be a great example in the docs
thank you very much
a
you’re welcome!
That would be a great example in the docs
Good idea! You could make an issue to ask for such an example to be added? https://github.com/Kotlin/kotlinx.serialization/issues/new/choose
j
sure