feat: resolve map of primitives#3044
Conversation
31a2370 to
15d7d6e
Compare
Adds Map<String, Any?> overload for resolveStructureValue(), enabling cleaner API for structured flags using Kotlin collections instead of JSON types. API (backward compatible): - resolveStructureValue(flagKey, JSONObject): JSONObject (existing) - resolveStructureValue(flagKey, Map): Map (new overload) The Map overload returns only primitives, null, nested Maps, and Lists - no JSONObject or JSONArray types. Implementation: - JsonExtensions.kt: Recursive bidirectional Map↔JSON conversion - String.toMap(): Direct JSON string → Map parsing - FlagValueConverter: Recognizes Map::class for OBJECT type - DatadogFlagsClient: Delegates to resolveValue with conversion - NoOpFlagsClient: Returns default map Benefits: - Backward compatible - existing JSONObject API unchanged - Type determines format - input type matches output type - Enables OpenFeature integration without JSON conversion issues
Adds JSONObject and JSONArray method calls used in JsonExtensions.kt: - JSONObject.constructor(String): Parse JSON strings - JSONObject.get/put: Get and set values - JSONArray.get/put: Get and add elements These methods are used for recursive Map↔JSON conversion and are safe within the context of the conversion logic.
45fdc80 to
03f969e
Compare
|
🎯 Code Coverage * Fix with Cursor requires Datadog plugin ≥v2.17.0 🔗 Commit SHA: d4de1af | Docs | Datadog PR Page | Was this helpful? Give us feedback! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feature/flags-ofeat #3044 +/- ##
=======================================================
+ Coverage 71.13% 71.17% +0.04%
=======================================================
Files 862 863 +1
Lines 31361 31400 +39
Branches 5277 5289 +12
=======================================================
+ Hits 22306 22347 +41
+ Misses 7557 7552 -5
- Partials 1498 1501 +3
🚀 New features to boost your workflow:
|
03f969e to
70829d1
Compare
70829d1 to
d6c35fd
Compare
| null -> JSONObject.NULL | ||
| is Map<*, *> -> { | ||
| // Convert keys to String (supports non-String keys via toString()) | ||
| @Suppress("UNCHECKED_CAST") |
| } | ||
| is List<*> -> { | ||
| @Suppress("UNCHECKED_CAST") | ||
| (value as List<Any?>).toJSONArray() |
There was a problem hiding this comment.
you can change receiver type from List<Any?>.toJSONArray to List<*>.toJSONArray at the function declaration and then cast is not needed here
| val fakeKey1Value = forge.anAlphabeticalString() | ||
| val fakeKey2Value = forge.anInt() | ||
| val fakeFlagValue = JSONObject().apply { | ||
| put("key1", forge.anAlphabeticalString()) | ||
| put("key2", forge.anInt()) | ||
| put("key1", fakeKey1Value) | ||
| put("key2", fakeKey2Value) |
There was a problem hiding this comment.
nit: looks like a redundant change
| assertThat(result[key1]).isEqualTo(value1) | ||
| assertThat(result["number"]).isEqualTo(value2) | ||
| assertThat(result["bool"]).isEqualTo(boolVal) | ||
| assertThat(result["double"]).isEqualTo(doubleVal) |
There was a problem hiding this comment.
you may want to use com.datadog.tools.unit.assertj.JsonObjectAssert for such assertions
typotter
left a comment
There was a problem hiding this comment.
Thanks, Nikita. ptal with the changes.
| val fakeKey1Value = forge.anAlphabeticalString() | ||
| val fakeKey2Value = forge.anInt() | ||
| val fakeFlagValue = JSONObject().apply { | ||
| put("key1", forge.anAlphabeticalString()) | ||
| put("key2", forge.anInt()) | ||
| put("key1", fakeKey1Value) | ||
| put("key2", fakeKey2Value) |
| assertThat(result[key1]).isEqualTo(value1) | ||
| assertThat(result["number"]).isEqualTo(value2) | ||
| assertThat(result["bool"]).isEqualTo(boolVal) | ||
| assertThat(result["double"]).isEqualTo(doubleVal) |
|
/merge |
|
View all feedbacks in Devflow UI.
This pull request is not mergeable according to GitHub. Common reasons include pending required checks, missing approvals, or merge conflicts — but it could also be blocked by other repository rules or settings.
The expected merge time in
Tests failed on this commit 5abf301: What to do next?
|
|
/remove |
|
View all feedbacks in Devflow UI.
This merge request was already processed and can't be unqueued anymore. To get help about command usage, write If you need support, contact us on Slack #devflow with those details! |
|
/merge |
|
View all feedbacks in Devflow UI.
The expected merge time in
|
What does this PR do?
Adds a Map<String, Any?> overload for
resolveStructureValue(), providing a cleaner Kotlin collectionsAPI for structured flags without JSONObject types.
Motivation
The existing
resolveStructureValue()returns JSONObject, which:This overload enables direct Map-based flag resolution with automatic recursive conversion of nested structures (maps and lists).
Additional Notes
API (backward compatible):
Key implementation:
Benefits:
Review checklist (to be filled by reviewers)