File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
ktoml-core/src/commonTest/kotlin/com/akuleshov7/ktoml/encoders Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import com.akuleshov7.ktoml.Toml
44import com.akuleshov7.ktoml.TomlOutputConfig
55import com.akuleshov7.ktoml.annotations.*
66import com.akuleshov7.ktoml.writers.IntegerRepresentation.*
7+ import kotlinx.serialization.EncodeDefault
8+ import kotlinx.serialization.ExperimentalSerializationApi
79import kotlinx.serialization.Serializable
810import kotlin.test.Ignore
911import kotlin.test.Test
@@ -315,4 +317,37 @@ class EncodingAnnotationTest {
315317 """ .trimIndent()
316318 )
317319 }
320+
321+ @OptIn(ExperimentalSerializationApi ::class )
322+ @Test
323+ fun encodeDefaultAnnotation () {
324+ @Serializable
325+ data class Foo (
326+ @EncodeDefault(EncodeDefault .Mode .ALWAYS )
327+ val a : Int = 1 ,
328+ @EncodeDefault(EncodeDefault .Mode .NEVER )
329+ val b : Int = 2 ,
330+ val c : Int = 3
331+ )
332+
333+ assertEncodedEquals(
334+ value = Foo (),
335+ expectedToml = """
336+ a = 1
337+ c = 3
338+ """ .trimIndent(),
339+ )
340+
341+ assertEncodedEquals(
342+ value = Foo (),
343+ expectedToml = """
344+ a = 1
345+ """ .trimIndent(),
346+ tomlInstance = Toml (
347+ outputConfig = TomlOutputConfig (
348+ ignoreDefaultValues = true ,
349+ )
350+ )
351+ )
352+ }
318353}
You can’t perform that action at this time.
0 commit comments