Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properties.encodeToStringMap when a map passed to it return all keys and values with index #2641

Open
mobinyardim opened this issue Apr 18, 2024 · 0 comments
Labels

Comments

@mobinyardim
Copy link

mobinyardim commented Apr 18, 2024

I ran the code below and couldn't figure out why the output is behaving this way.
The Code:

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.properties.Properties
import kotlinx.serialization.properties.encodeToStringMap


@OptIn(ExperimentalSerializationApi::class)
fun main(): Unit {
    val map = Properties.encodeToStringMap(mapOf("key" to "value"))
    println(map)
}

Output:
{0=key, 1=value}
My expected output:
{key=value}

I encountered this behavior when I have a Box class with a field named 'content' of generic type. When I specify the type of 'content' as Map and attempt to encode the Box class instance to a map, it behaves as I described above. I believe this behavior is inappropriate.

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.properties.Properties
import kotlinx.serialization.properties.encodeToStringMap

@Serializable
class Box<out T>(
    val content: T
)

@OptIn(ExperimentalSerializationApi::class)
fun main(): Unit {
    val boxOfMap = Box(mapOf("key" to "value"))
    println(Properties.encodeToStringMap(boxOfMap))
}

output:
{content.0=key, content.1=value}

what I expect:
{content.key=value}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant