2023-01-12 11:52:54 +03:00
|
|
|
package center.sciprog.attributes
|
|
|
|
|
|
|
|
import kotlinx.serialization.json.Json
|
|
|
|
import kotlinx.serialization.serializer
|
|
|
|
import kotlin.test.Test
|
|
|
|
import kotlin.test.assertEquals
|
|
|
|
|
|
|
|
internal class AttributesSerializationTest {
|
|
|
|
|
2023-02-11 17:14:00 +03:00
|
|
|
internal class TestAttributeContainer(val attributes: Attributes)
|
|
|
|
|
|
|
|
// internal object TestContainerAttribute: SerializableAttribute<TestAttributeContainer>("container", se)
|
|
|
|
|
2023-01-12 11:52:54 +03:00
|
|
|
internal object TestAttribute : SerializableAttribute<Map<String, String>>("test", serializer())
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun restore() {
|
2023-02-11 17:14:00 +03:00
|
|
|
//
|
|
|
|
// val serializersModule = SerializersModule {
|
|
|
|
// contextual(AttributesSerializer(setOf()))
|
|
|
|
// }
|
2023-01-12 11:52:54 +03:00
|
|
|
val serializer = AttributesSerializer(setOf(NameAttribute, TestAttribute))
|
|
|
|
|
|
|
|
|
|
|
|
val attributes = Attributes {
|
|
|
|
NameAttribute("myTest")
|
|
|
|
TestAttribute(mapOf("a" to "aa", "b" to "bb"))
|
|
|
|
}
|
|
|
|
|
|
|
|
val serialized = Json.encodeToString(serializer, attributes)
|
|
|
|
println(serialized)
|
|
|
|
|
|
|
|
val restored = Json.decodeFromString(serializer, serialized)
|
|
|
|
|
|
|
|
assertEquals(attributes, restored)
|
|
|
|
}
|
|
|
|
}
|