@@ -105,8 +105,8 @@ public static EvaluationContext mapEnvironmentDocumentToContext(
105105 // Map identity overrides
106106 JsonNode identityOverrides = environmentDocument .get ("identity_overrides" );
107107 if (identityOverrides != null && identityOverrides .isArray ()) {
108- Map <String , SegmentContext > identityOverrideSegments =
109- mapIdentityOverridesToSegments ( identityOverrides );
108+ Map <String , SegmentContext > identityOverrideSegments = mapIdentityOverridesToSegments (
109+ identityOverrides );
110110 segments .putAll (identityOverrideSegments );
111111 }
112112
@@ -163,9 +163,7 @@ private static Map<String, SegmentContext> mapIdentityOverridesToSegments(
163163 .withFeatureKey (feature .get ("id" ).asText ())
164164 .withName (feature .get ("name" ).asText ())
165165 .withEnabled (featureState .get ("enabled" ).asBoolean ())
166- .withValue (featureState .get ("feature_state_value" ) != null
167- ? featureState .get ("feature_state_value" ).asText ()
168- : null )
166+ .withValue (getFeatureStateValue (featureState , "feature_state_value" ))
169167 .withPriority (Double .NEGATIVE_INFINITY ); // Highest possible priority
170168 overridesKey .add (featureContext );
171169 }
@@ -234,7 +232,7 @@ private static List<SegmentRule> mapEnvironmentDocumentRulesToContextRules(
234232 SegmentCondition segmentCondition = new SegmentCondition ()
235233 .withProperty (condition .get ("property_" ).asText ())
236234 .withOperator (SegmentConditions .valueOf (condition .get ("operator" ).asText ()))
237- .withValue (condition .get ("value" ));
235+ .withValue (condition .get ("value" ). asText () );
238236 conditions .add (segmentCondition );
239237 }
240238 }
@@ -294,6 +292,24 @@ private static String getFeatureStateKey(JsonNode featureState) {
294292 return "" ;
295293 }
296294
295+ private static Object getFeatureStateValue (JsonNode featureState , String fieldName ) {
296+ JsonNode valueNode = featureState .get (fieldName );
297+ if (valueNode .isTextual () || valueNode .isLong ()) {
298+ return valueNode .asText ();
299+ } else if (valueNode .isNumber ()) {
300+ if (valueNode .isInt ()) {
301+ return valueNode .asInt ();
302+ } else {
303+ return valueNode .asDouble ();
304+ }
305+ } else if (valueNode .isBoolean ()) {
306+ return valueNode .asBoolean ();
307+ } else if (valueNode .isArray () || valueNode .isObject ()) {
308+ return valueNode ;
309+ }
310+ return null ;
311+ }
312+
297313 /**
298314 * Maps a single feature state to feature context.
299315 *
@@ -308,9 +324,7 @@ private static FeatureContext mapFeatureStateToFeatureContext(JsonNode featureSt
308324 .withFeatureKey (feature .get ("id" ).asText ())
309325 .withName (feature .get ("name" ).asText ())
310326 .withEnabled (featureState .get ("enabled" ).asBoolean ())
311- .withValue (featureState .get ("feature_state_value" ) != null
312- ? featureState .get ("feature_state_value" ).asText ()
313- : null );
327+ .withValue (getFeatureStateValue (featureState , "feature_state_value" ));
314328
315329 // Handle multivariate feature state values
316330 JsonNode multivariateValues = featureState .get ("multivariate_feature_state_values" );
@@ -321,7 +335,8 @@ private static FeatureContext mapFeatureStateToFeatureContext(JsonNode featureSt
321335 sortedMultivariate .sort ((a , b ) -> a .get ("id" ).asText ().compareTo (b .get ("id" ).asText ()));
322336 for (JsonNode multivariateValue : sortedMultivariate ) {
323337 FeatureValue variant = new FeatureValue ()
324- .withValue (multivariateValue .get ("multivariate_feature_option" ).get ("value" ).asText ())
338+ .withValue (getFeatureStateValue (
339+ multivariateValue .get ("multivariate_feature_option" ), "value" ))
325340 .withWeight (multivariateValue .get ("percentage_allocation" ).asDouble ());
326341 variants .add (variant );
327342 }
0 commit comments