kotlinx.serialization
kotlinx.serialization copied to clipboard
Introduce new StringProperties object that can encode and decode properties from a string
Introduce a new StringProperties object that can encode and decode properties from a string format. This new object is heavily based on the existing kotlinx.serialization Properties object.
- for encoding, it first encodes the input Kotlin object a string map using
Propertiesand them formats that string map to a properties file. Some parameters can be passed to customise the encoding format, such as key/value separator, number of spaces before and after the key/value separator, and line separator. - for decoding, it first parses the input data as a string map and then decodes it into a Kotlin object using
Properties. The parsers handles comments, whitespaces, escapes, natural lines vs logical lines. The intent is to support the same format as the Java Properties API (doc). For now, unicode characters are not implemented.
The implementation has been inspired a lot from the gist made by https://github.com/RaphaelTarita linked in this issue. I have added many unit tests that show how it is used and how it behaves.
This PR should fix https://github.com/Kotlin/kotlinx.serialization/issues/1152 and KT-42716.