Skip to content

Use Kotlin Serialization and support KMP #2

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hvisser
Copy link

@hvisser hvisser commented Jun 14, 2025

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 the UNKNOWN constant of the given enums.
  • ConditionSerializer implements the check that any unknown condition properties will make the condition never match. Previously the Condition had a matchNever flag for this purpose.

These and other serializers should be setup in a SerializerModule when parsing the config directly. An appRemoteConfigSerializersModule 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 a JsonObject and one that takes a KSerializer 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

  • Fix publishing
  • Add iOS target

Copy link

@IuliaSTANA IuliaSTANA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great improvements, thank you!

@johankool
Copy link
Member

Thanks! Will take a closer look soon, but looks good to me so far. Regarding signing and verification: that needs to be aligned with the Swift version. I had initially an approach with sodium, but went with a more common Curve25519. See https://github.com/egeniq/app-remote-config/blob/main/Sources/AppRemoteConfig/Config%2BSigning.swift . There is no usage yet of signing in production so we're still flexible there.

@hvisser
Copy link
Author

hvisser commented Jun 16, 2025

Yeah there might be some issues re: expectations that Kotlin Serialization is making when deserializing, for example "ignoreUnknownKeys" is pretty important for cases where the config json structure for any reason has additional keys. Would be nice to solve that in the library somehow if possible. There might be other edge cases still, this is mostly just porting the existing logic. As I have no apps using this it's a bit hard for me to do a "real" test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants