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

无法正确序列化空字节 #53

Open
PigeonYuze opened this issue Jan 17, 2023 · 0 comments
Open

无法正确序列化空字节 #53

PigeonYuze opened this issue Jan 17, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@PigeonYuze
Copy link

PigeonYuze commented Jan 17, 2023

内容描述
使用Yaml.encodeToString去序列化一个含空charclass得到的内容无法正确序列化

fun main(args: Array<String>) {
    val encodeToString = Yaml.encodeToString(CharClassTest(' '))
    println(encodeToString)
}

@kotlinx.serialization.Serializable
class CharClassTest(val char: Char)

输出的结果

char:
(char: 后面还包含有2个空字节)

如果以此进行反序列化则无法正常反序列化,抛出YamlDecodingException错误

Exception in thread "main" net.mamoe.yamlkt.YamlDecodingException: Top-level decoder: deserializing nested class for '1' in 'kotlin.collections.LinkedHashMap'
char:
^ at line 1, column 8

at net.mamoe.yamlkt.internal.YamlUtils__ContextualExceptionKt.contextualDecodingException(ContextualException.kt:154)
at net.mamoe.yamlkt.internal.YamlUtils.contextualDecodingException(Unknown Source)
at net.mamoe.yamlkt.internal.YamlDecoder$AbstractDecoder.decodeSerializableElement(YamlDecoder.kt:181)
at kotlinx.serialization.encoding.CompositeDecoder$DefaultImpls.decodeSerializableElement$default(Decoding.kt:537)
at kotlinx.serialization.internal.MapLikeSerializer.readElement(CollectionSerializers.kt:111)
at kotlinx.serialization.internal.MapLikeSerializer.readElement(CollectionSerializers.kt:84)
at kotlinx.serialization.internal.AbstractCollectionSerializer.readElement$default(CollectionSerializers.kt:51)
at kotlinx.serialization.internal.AbstractCollectionSerializer.merge(CollectionSerializers.kt:36)
at kotlinx.serialization.internal.AbstractCollectionSerializer.deserialize(CollectionSerializers.kt:43)
at net.mamoe.yamlkt.YamlNullableDynamicSerializer.deserialize(YamlNullableDynamicSerializer.kt:86)
at net.mamoe.yamlkt.Yaml.decodeFromString(Yaml.kt:162)
at net.mamoe.yamlkt.Yaml.decodeAnyFromString(Yaml.kt:229)

环境描述
使用的版本: net.mamoe.yamlkt:yamlkt-jvm:0.12.0
jdk:

java 17.0.1 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)

@Him188 Him188 added the bug Something isn't working label Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants