From 8d66cf84040ce9777e3dd55cecc36dc6b262c010 Mon Sep 17 00:00:00 2001 From: Mark Siebert Date: Mon, 20 Apr 2026 09:58:25 -0700 Subject: [PATCH] fix(openfeature): handle JSONObject/JSONArray in objectToValue Object variant values arrive from RemoteFlagsProvider and the local evaluator as org.json.JSONObject / JSONArray (the core SDK's public SelectedVariant shape). The OpenFeature provider's objectToValue had no branches for these types, so they fell through to new Value(toString()) and surfaced as a plain String Value instead of a Structure. Callers of getObjectEvaluation got a non-null Value whose asStructure() was null, breaking spec-compliant OpenFeature usage. This adds JSONObject, JSONArray, and JSONObject.NULL handling in objectToValue. Purely additive: no core SDK changes, no signature changes, no impact on direct SelectedVariant consumers. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../openfeature/MixpanelProvider.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java b/openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java index ecb479b..251eea9 100644 --- a/openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java +++ b/openfeature-provider/src/main/java/com/mixpanel/openfeature/MixpanelProvider.java @@ -7,6 +7,8 @@ import com.mixpanel.mixpanelapi.featureflags.provider.BaseFlagsProvider; import com.mixpanel.mixpanelapi.featureflags.provider.LocalFlagsProvider; import dev.openfeature.sdk.*; +import org.json.JSONArray; +import org.json.JSONObject; import java.util.logging.Level; import java.util.logging.Logger; @@ -263,6 +265,9 @@ private static Value objectToValue(Object obj) { if (obj == null) { return new Value(); } + if (obj == JSONObject.NULL) { + return new Value(); + } if (obj instanceof Boolean) { return new Value((Boolean) obj); } @@ -310,6 +315,22 @@ private static Value objectToValue(Object obj) { } return new Value(values); } + if (obj instanceof JSONObject) { + JSONObject json = (JSONObject) obj; + Map structure = new HashMap<>(); + for (String key : json.keySet()) { + structure.put(key, objectToValue(json.get(key))); + } + return new Value(new ImmutableStructure(structure)); + } + if (obj instanceof JSONArray) { + JSONArray arr = (JSONArray) obj; + ArrayList values = new ArrayList<>(); + for (int i = 0; i < arr.length(); i++) { + values.add(objectToValue(arr.get(i))); + } + return new Value(values); + } return new Value(obj.toString()); } }