-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add Serialization Configuration for Char and Upgrade Kotlin #75
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where should I place this test? Should it be in an existing test class or should I create a new class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same file is a good one.
@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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
fix #53 , #68
✨ Add Serialization Configuration for Char
When creating a Yaml object, you can specify the handling logic for char:
Among these,
UNICODE_CODE
supports the serialization and deserialization ofUnicode
. You can now handleChar
with 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.serialization
to1.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.