Use Kotlin Serialization and support KMP #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR removes the use of
JSONObject
and manual parsing and replaces it with Kotlin Serialization. In addition it's now a multiplatform module.For parsing and checking the config a couple of custom serializers are used. Parsing of the config can be directly integrated in Retrofit or Ktor so that a server response is correctly deserialized into a
Config
instance.UnknownValueSerializer
for parsing the enum values. When a parsing error occurs due to a new or unknown value it will fallback to theUNKNOWN
constant of the given enums.ConditionSerializer
implements the check that any unknown condition properties will make the condition never match. Previously theCondition
had amatchNever
flag for this purpose.These and other serializers should be setup in a
SerializerModule
when parsing the config directly. AnappRemoteConfigSerializersModule
property has been added for this purpose.As a convenience and to be compatible with the current version, a config can also be created by passing a json string to the
Config
function.Type safe config objects
There are two versions of
resolve
: one that returns aJsonObject
and one that takes aKSerializer
to deserialize the config into a typed object. In practice working with a typed object is more convenient, but care should be taken that unknown keys are ignored and that the settings object has proper defaults. When passing the config as a json string, unknown keys are ignored by default. When integrated as part of Ktor for example, the settings objects need to be annotated correctly or a custom serializer should be used to handle failure cases.Tests
The existing tests have been moved over and updated. The config tests show deserializing to a custom object. Some of the tests have been split out to their own file.
Signing / verification
The verification of signatures has been removed temporarily. This is probably best as a separate module anyway so that one can opt to verify the signature if needed. I'm happy to give that a stab too if this PR is acceptable.
Other stuff
I changed a few minor things to be more idiomatic kotlin and I've added
internal
modifiers to hide specific types from consumers, though this might not be fully complete.I didn't do the moving of files in a separate commit, so some moves show up now while others don't. Sorry about that :)
TODO