-
Notifications
You must be signed in to change notification settings - Fork 50
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
Primitive serialization not working? #300
Comments
This seems to be a recurring issue (see #30 (comment)), so I'd love to fix this. Unfortunately, I don't have the time to do this myself right now. If you're interested in submitting a PR to fix the issue, I'd be more than happy to talk through your ideas, provide early feedback etc. to help you. |
This issue has been automatically marked as stale because it has not had any activity in the last 60 days. It will automatically be closed if no further activity occurs in the next seven days to enable maintainers to focus on the most important issues. |
This issue has been automatically closed because it has not had any recent activity. |
Could this be re-opened @charleskorn? I currently have to have twice the serializers as I should do in my project as I have to have separate ones for Json compared to Yaml: Json: object JsonLocalDateSerializer : KSerializer<LocalDate> {
override val descriptor = PrimitiveSerialDescriptor(LocalDate::class.simpleName as String, PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: LocalDate) {
encoder.encodeString(value.toString())
}
override fun deserialize(decoder: Decoder): LocalDate {
return LocalDate.parse(decoder.decodeString())
}
} Yaml: object YamlLocalDateSerializer : KSerializer<LocalDate> {
override val descriptor = PrimitiveSerialDescriptor(LocalDate::class.simpleName as String, PrimitiveKind.STRING)
override fun serialize(encoder: Encoder, value: LocalDate) {
encoder.encodeString(value.toString())
}
override fun deserialize(decoder: Decoder): LocalDate {
return LocalDate.parse(decoder.beginStructure(descriptor).decodeStringElement(descriptor, 0))
}
}
|
Happy to reopen this, but I do not have time to work on this myself. I'd happily review a PR if you (or anyone else) is keen to see this happen. |
This issue has been automatically marked as stale because it has not had any activity in the last 60 days. It will automatically be closed if no further activity occurs in the next seven days to enable maintainers to focus on the most important issues. |
@charleskorn Can you freeze this |
Hi, @russellbanks. This issue might have been resolved when #568 was closed. Could you please check version 0.61.0 and let us know if you still have the problem? |
Describe the bug
Primitive deserialization is not working.
Reproduction repo
This serializer class works for JSON but not for YAML.
Steps to reproduce
Create simple primitive serializer as described in docs and try to deserialize a value.
Expected behaviour
Same behaviour as in JSON.
It works if I change deserializer to this:
but this way is not compatible with JSON and doesn't seem clean in general.
Actual behaviour
Version information
Any other information
No response
The text was updated successfully, but these errors were encountered: