• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 @file:UseSerializers(MultiplyingIntHolderSerializer::class, MultiplyingIntSerializer::class)
6 
7 package kotlinx.serialization.features
8 
9 import kotlinx.serialization.*
10 import kotlinx.serialization.json.*
11 import kotlin.test.*
12 
13 @Serializable
14 data class Carrier2(
15     val a: IntHolder,
16     val i: Int,
17     val nullable: Int?,
18     val nullableIntHolder: IntHolder?,
19     val nullableIntList: List<Int?> = emptyList(),
20     val nullableIntHolderNullableList: List<IntHolder?>? = null
21 )
22 
23 class UseSerializersTest {
<lambda>null24     private val jsonWithDefaults = Json { encodeDefaults = true }
25 
26     @Test
testOnFilenull27     fun testOnFile() {
28         val str = jsonWithDefaults.encodeToString(
29             Carrier2.serializer(),
30             Carrier2(IntHolder(42), 2, 2, IntHolder(42))
31         )
32         assertEquals("""{"a":84,"i":4,"nullable":4,"nullableIntHolder":84,"nullableIntList":[],"nullableIntHolderNullableList":null}""", str)
33     }
34 }
35