Add Serialization Configuration for Char and Upgrade Kotlin#75
Add Serialization Configuration for Char and Upgrade Kotlin#75Him188 merged 7 commits intoHim188:masterfrom
Conversation
feat: Add char serialization using Unicode code points fix: Correct serialization for chars with special characters
Also: Updated kotlinx.serialization to 1.7.0 for compatibility
|
😊 |
yamlkt/src/commonMain/kotlin/net.mamoe.yamlkt/internal/YamlDecoder.kt
Outdated
Show resolved
Hide resolved
yamlkt/src/commonMain/kotlin/net.mamoe.yamlkt/YamlConfigurationInternal.kt
Outdated
Show resolved
Hide resolved
yamlkt/src/commonMain/kotlin/net.mamoe.yamlkt/YamlConfigurationInternal.kt
Outdated
Show resolved
Hide resolved
yamlkt/src/commonMain/kotlin/net.mamoe.yamlkt/YamlConfigurationInternal.kt
Outdated
Show resolved
Hide resolved
| @Test | ||
| fun testCharEscape() { | ||
| assertEquals("\" \"", doubleChar.encodeToString<Char>(' ')) | ||
| assertEquals("\' \'", singleChar.encodeToString<Char>(' ')) | ||
| assertEquals("\' \'", PLAIN.encodeToString<Char>(' ')) | ||
| assertEquals("32", unicode.encodeToString<Char>(' ')) | ||
|
|
||
| assertEquals(' ', unicode.decodeFromString<Char>("32")) | ||
| } | ||
|
|
There was a problem hiding this comment.
IIRC class properties are handled differently than top-level values. We should also test serializable classes:
@Serializable
class Container(
val c: Char,
)
There was a problem hiding this comment.
Where should I place this test? Should it be in an existing test class or should I create a new class?
|
@Him188 Do you think we should support some special codes? For example, should we support deserialization of 'a' from |
|
If that's in the YAML spec then we are good to support them, if not, then we have to consider whether they are really needed. This PR is already good enough. Let's focus on fixing the bug first. |
|
@Him188 Hey! When do you think this PR can be merged? Thanks! |
|
Thanks for pinging me. Merged. |
fix #53 , #68
✨ Add Serialization Configuration for Char
When creating a Yaml object, you can specify the handling logic for char:
Among these,
UNICODE_CODEsupports the serialization and deserialization ofUnicode. You can now handleCharwith logic similar toByte.Additionally, escaping support for char serialization has been added to prevent certain characters (like
'\n','"', etc.) from being incorrectly input into the content. They will now be escaped with quotes.⬆️ Upgrade kotlin
Upgraded the project's kotlin version to
2.0.0. For compatibility, also updatedkotlinx.serializationto1.7.0.I encountered the same compilation issue as in #72 while attempting the update and fixed it by referring to the corresponding comment.
Therefore, theoretically, this PR should also support the content in #72 and it seems it should fix #67 as well.