https://kotlinlang.org logo
#serialization
Title
# serialization
t

Tobias Wohlfarth

02/17/2023, 4:32 PM
I'm building a little client application with Ktor accessing a Third-Party-API. The API give a response with the following part
Copy code
fullsize_url: "https://...."
image_url: "https://...."
In my Data Class these should be represented by specific URL Types. Which one should i use java.net.URL or io.ktor.http.Url ? Is there a ready to use Serializer for any of those both?
a

Adam S

02/17/2023, 5:43 PM
I think there's a ready-to-use serializer for URLs in https://github.com/Kantis/ks3
Copy code
@file:UseSerializers(
  UrlSerializer::class,
  FooSerializer::class,
  BarSerializer::class,
  // ...
)
you could also consider using typealiases
Copy code
typealias UrlSerialized = @Serialized(with = UrlSerializer::class) URL
that would save having to copy-paste the
@file:UserSerializers()
in multiple files
e

Emil Kantis

02/18/2023, 4:58 PM
I think there is a typealias included :)
UrlAsString
, unless it was added after 0.0.2
10 Views