kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

Make JsonConfiguration itself @Serializable

Open hfhbd opened this issue 5 years ago • 4 comments

What is your use-case and why do you need this feature? I would like to store the JsonConfiguration itself in a Json file and read them at startup. This allows to use different behavior with a simple change in the config files.

eg having a prod configuration and a debug configuration, which use a less strict Json De-/Encoder or uses pretty print.

Of course, the JsonConfiguration for reading the json configs must be static defined and cannot be defined in the config file.

Describe the solution you'd like Add @Serializable to JsonConfiguration

Current workaorund: Implement a custom serializer, which I did for my project

hfhbd avatar May 06 '20 10:05 hfhbd

Closing for the reason described in https://github.com/Kotlin/kotlinx.serialization/pull/877#pullrequestreview-441582372

sandwwraith avatar Jul 02 '20 11:07 sandwwraith

Its fine, my implementation was only adding 1 attribute :) But I would like to have the option changing the json behaviour with a config file, even with the new API.

hfhbd avatar Jul 07 '20 08:07 hfhbd

https://github.com/Kotlin/kotlinx.serialization/pull/877#issuecomment-1081826204

sandwwraith avatar Mar 29 '22 13:03 sandwwraith

Note that current JsonConfiguration is useless for creating new Json instances (as it was intended to be used mainly in encoders/decoders), so one still would need to use JsonBuilder for that.

sandwwraith avatar Mar 29 '22 13:03 sandwwraith