https://kotlinlang.org logo
Title
a

Advitiay Anand

02/08/2022, 8:33 PM
Hi everyone, I've got a Kotlin project (not Android) that involves many variables with user-specific values (e.g. username, password, time-table) I would like this data to be moved out of the code, and into a modifiable file. The goal is to make it easy for non-coders to modify values and use the program. What are my best bets here? (JSON / YAML / etc). And what library should I be using? Here's a link to the project: https://github.com/adizcode/ProxyMate
t

Tim Oltjenbruns

02/08/2022, 8:49 PM
In the past I’ve gone with Gson and/or Moshi, Kotlin serialization is an option as well, I have no experience with it though. As for the decision between json/yaml, I usually make that decision based on whether there will be repeated values in the data or not. If there is a lot of repeated data, with yaml the user can use anchors and aliases to make that easier to maintain. Otherwise go with json.
💡 1
:thank-you: 1
👍 1
p

Paul Griffith

02/08/2022, 9:17 PM
TOML is closer to plain text than JSON (less repeated quotes and braces and such) and has less footguns than YAML
👍 1
🤔 1
t

Tim Oltjenbruns

02/08/2022, 9:19 PM
alternatively, if the config is simple… properties file?
2
a

Advitiay Anand

02/08/2022, 9:20 PM
Thank you for the responses. @Tim Oltjenbruns I don't actually know about properties files. Are they like .env files?
p
JVM-only, though it’d be easy enough to write a parser on another platform
a

Advitiay Anand

02/08/2022, 9:25 PM
This is great. I'll certainly read about using properties. Thanks :))
o

Oliver.O

02/08/2022, 9:31 PM
This excellent pure Kotlin config library together with YAML seems like a good option in my view: https://github.com/sksamuel/hoplite
1
💡 1
:thank-you: 1