• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.serialization.features
6 
7 import kotlinx.serialization.*
8 import kotlinx.serialization.builtins.*
9 import kotlinx.serialization.json.*
10 import kotlinx.serialization.modules.*
11 import kotlin.test.*
12 import kotlin.uuid.*
13 
14 class UuidTest : JsonTestBase() {
15     @Test
testPlainUuidnull16     fun testPlainUuid() {
17         val uuid = Uuid.random()
18         assertJsonFormAndRestored(Uuid.serializer(), uuid, "\"$uuid\"")
19     }
20 
21     // TODO: write a test without @Contextual after 2.1.0 release
22     @Serializable
23     data class Holder(@Contextual val uuid: Uuid)
24 
<lambda>null25     val json = Json { serializersModule = serializersModuleOf(Uuid.serializer()) }
26 
27     @Test
testNestednull28     fun testNested() {
29         val fixed = Uuid.parse("bc501c76-d806-4578-b45e-97a264e280f1")
30         assertJsonFormAndRestored(
31             Holder.serializer(),
32             Holder(fixed),
33             """{"uuid":"bc501c76-d806-4578-b45e-97a264e280f1"}""",
34             json
35         )
36     }
37 }
38