Skip to content

Properties serializer does not handle map null value correctly. #1623

@devsvc

Description

@devsvc

Describe the bug
Properties serializer does not handle map null value correctly. Properties.encodeToMap serialized the key without value. So the map it encoded could not be decoded.

To Reproduce

class TestSer {

    @Serializable
    data class Data(
        val m: Map<String, String?> = mapOf()
    )

    @Test
    fun test() {
        val data = Data(mapOf(
            "a" to "1",
            "b" to null
        ))

        val map = Properties.encodeToMap(data)
        println(map)
        val data1: Data = Properties.decodeFromMap(map)
        println(data1)
    }

}

{m.0=a, m.1=1, m.2=b}

Expected behavior
map should be {m.0=a, m.1=1, m.2=b, m.3=null}

if it produce {m.a=1, m.b=null} will be much better

Environment

  • Kotlin version: [1.5.20]
  • Library version: [1.2.2]
  • Kotlin platforms: [JVM]
  • IDE version (if bug is related to the IDE) [Intellij Comunity 2021.2]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions