Skip to content

Commit

Permalink
refactor: Always include geary namespace in getClassFor, swap to prop…
Browse files Browse the repository at this point in the history
…erty polymorphism style
  • Loading branch information
0ffz committed Oct 18, 2024
1 parent 2db7f39 commit 093a8f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ class SerializersByMap(

//TODO allow this to work for all registered classes, not just components
override fun getClassFor(serialName: String, namespaces: List<String>): KClass<out Component> {
val defaultNamespaces = (namespaces + "geary").toSet()
val parsedKey = serialName.fromCamelCaseToSnakeCase()
return (if (parsedKey.hasNamespace())
serialName2Component[parsedKey]
else namespaces.firstNotNullOfOrNull { namespace ->
else defaultNamespaces.firstNotNullOfOrNull { namespace ->
serialName2Component["$namespace:$parsedKey"]
})
?: error("$parsedKey is not a component registered in any of the namespaces: $namespaces")
?: error("$parsedKey is not a component registered in any of the namespaces: $defaultNamespaces")
}

override fun <T : Component> getSerializerFor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.mineinabyss.geary.serialization.formats

import com.charleskorn.kaml.Yaml
import com.charleskorn.kaml.YamlConfiguration
import com.charleskorn.kaml.decodeFromStream
import com.charleskorn.kaml.encodeToStream
import com.charleskorn.kaml.*
import com.mineinabyss.geary.serialization.formats.Format.ConfigType
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.SerializationStrategy
Expand All @@ -22,13 +19,15 @@ class YamlFormat(
configuration = YamlConfiguration(
encodeDefaults = false,
strictMode = false,
polymorphismStyle = PolymorphismStyle.Property
)
)

val regularYaml = Yaml(
serializersModule = module,
configuration = YamlConfiguration(
encodeDefaults = false,
polymorphismStyle = PolymorphismStyle.Property
)
)

Expand Down

0 comments on commit 093a8f1

Please sign in to comment.