Skip to content

Conversation

@lesnitsky
Copy link
Member

@lesnitsky lesnitsky commented Aug 2, 2021

Description

This PR adds support for nested json values

Related Issues

Closes #2074
Closes #6074

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

@lesnitsky lesnitsky requested a review from Salakar August 2, 2021 16:10
@google-cla google-cla bot added the cla: yes label Aug 2, 2021
@lesnitsky lesnitsky changed the title @lesnitsky/remote config json values [remote_config]: support nested json values Aug 2, 2021
@lesnitsky lesnitsky changed the title [remote_config]: support nested json values feat(remote_config): support nested json values Aug 2, 2021
@lesnitsky lesnitsky force-pushed the @lesnitsky/remote_config_json_values branch from f768248 to bd37ff9 Compare August 3, 2021 11:18
@lesnitsky lesnitsky marked this pull request as ready for review August 3, 2021 11:51
defaultParameters.map(
(key, value) => MapEntry(
key,
_isSupportedType(value) ? value : json.encode(value),
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that should be the responsibility of setDefaults to encode a value. I would expect the function to be called with an already serialized parameter

Copy link
Member Author

Choose a reason for hiding this comment

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

Map<String, dynamic> type of the argument suggests you can pass anything inside (which happened in #2074).
Native APIs are not symmetric, iOS does have json-related helper, android doesn't. Since we can't explicitly forbid non-primitive types on type level, I think having this helper method would be useful. An alternative would be asserting incoming value types and throwing on anything other than bool, number, or string, but I don't see this behavior as developer-friendly, especially taking into account we can provide a convenient method.

Agree, that encoding should be done not on a method channel level, so moving to packages/firebase_remote_config/firebase_remote_config/lib/src/remote_config.dart

Copy link
Contributor

Choose a reason for hiding this comment

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

Since we can't explicitly forbid non-primitive types on type level, I think having this helper method would be useful

I disagree. Instead I think throwing is the way to go.

The fact that Dart type system does not allows us to statically prevent values other than primitive doesn't mean that we should handle non-primitive values.

Map<String, dynamic> is the Dart standard for JSON structures allowing only primitives.
Most function taking such Map as parameter consider non-primitive values as an error.

Using "encode" here is non-standard and is trying to patch mistakes from the users.

Copy link
Member Author

@lesnitsky lesnitsky Aug 13, 2021

Choose a reason for hiding this comment

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

The fact that Dart type system does not allows us to statically prevent values other than primitive doesn't mean that we should handle non-primitive values.

dart not allowing us to prevent values other than primitives shouldn't limit us in making the API more developer-friendly either 😉

Using "encode" here is non-standard and is trying to patch mistakes from the users.

I don't see it as a patch for a mistake. A developer's will to pass a Map as a config value is hardly a mistake (as well as willing to read that Map back via asJson)

@lesnitsky lesnitsky requested a review from rrousselGit August 4, 2021 10:47
@lesnitsky lesnitsky force-pushed the @lesnitsky/remote_config_json_values branch 3 times, most recently from 320cd93 to 0c71db5 Compare August 11, 2021 10:35
@lesnitsky lesnitsky force-pushed the @lesnitsky/remote_config_json_values branch 3 times, most recently from 887cf36 to 46d42ff Compare August 12, 2021 08:48
@lesnitsky lesnitsky force-pushed the @lesnitsky/remote_config_json_values branch from 46d42ff to 33921a7 Compare August 13, 2021 10:19
@lesnitsky
Copy link
Member Author

an alternative solution #6817

@lesnitsky
Copy link
Member Author

@kroikie could you please take a look at this one and give your opinion on which API is preferable? there's also an alternative to this PR, check out #6817

@kroikie
Copy link
Collaborator

kroikie commented Aug 23, 2021

@lesnitsky @rrousselGit would it be possible for us to let the call go through and if accepted on the native side then we do nothing and if rejected we bubble up the possibility that if an object is being used then it should be encoded first?

@lesnitsky
Copy link
Member Author

@kroikie letting the call go through is exactly what's currently happening. It leads to map serialization on java side, so {"a": ""b"} is being converted to {a=b} (or something similar, not sure how default java toString on maps works).So no error is propagated, but value is not deserialisable from that string

@kroikie
Copy link
Collaborator

kroikie commented Aug 24, 2021

The underlying Android and Web SDKs explicitly lists the types that can be used for defaults so I think it would be fair for us to do the same on the Dart side. So I think we should throw if the user is setting a default value that is not allowed. We should avoid transforming the user's data as much as possible.

@lesnitsky
Copy link
Member Author

closing in favor of #6817

@lesnitsky lesnitsky closed this Aug 25, 2021
@lesnitsky lesnitsky deleted the @lesnitsky/remote_config_json_values branch August 25, 2021 10:34
@firebase firebase locked and limited conversation to collaborators Sep 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

3 participants