From 8028c90a001d83e9a9c06d87c4e6ce1255d9fc32 Mon Sep 17 00:00:00 2001 From: Parth Suthar Date: Thu, 19 Mar 2026 13:08:29 -0400 Subject: [PATCH 1/2] fix: update the java openfeature examples to be compliant with openfeature --- .../server-side-sdks/java/java-openfeature.md | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/docs/sdk/server-side-sdks/java/java-openfeature.md b/docs/sdk/server-side-sdks/java/java-openfeature.md index e466acf5..8f9567ec 100644 --- a/docs/sdk/server-side-sdks/java/java-openfeature.md +++ b/docs/sdk/server-side-sdks/java/java-openfeature.md @@ -92,8 +92,28 @@ public class OpenFeatureExample { Use a Variable value by passing the Variable key, default value, and EvaluationContext to one of the OpenFeature flag evaluation methods. ```java -// Retrieve a boolean flag from the OpenFeature client -Boolean variableValue = openFeatureClient.getBooleanValue("boolean-flag", false, new MutableContext("user-1234")); +MutableContext context = new MutableContext("user-1234"); + +// Retrieve a boolean flag value +Boolean boolValue = openFeatureClient.getBooleanValue("boolean-flag", false, context); + +// Retrieve a string flag value +String stringValue = openFeatureClient.getStringValue("string-flag", "default", context); + +// Retrieve an integer flag value +Integer intValue = openFeatureClient.getIntegerValue("integer-flag", 0, context); + +// Retrieve a double flag value +Double doubleValue = openFeatureClient.getDoubleValue("double-flag", 0.0, context); + +// Use the returned values in your application logic +if (boolValue) { + // Feature is enabled + System.out.println("Feature is enabled! String value: " + stringValue); +} else { + // Feature is disabled, default value was returned + System.out.println("Feature is disabled"); +} ``` [//]: # 'wizard-evaluate-end' @@ -140,21 +160,27 @@ The OpenFeature spec for JSON flags allows for any type of valid JSON value to b For example the following are all valid default value types to use with OpenFeature: ```java +MutableContext context = new MutableContext("user-1234"); + // Invalid JSON values for the DevCycle SDK, will return defaults -openFeatureClient.getObjectValue("json-flag", new Value(new ArrayList(Arrays.asList("value1", "value2")))); -openFeatureClient.getObjectValue("json-flag", new Value(610)); -openFeatureClient.getObjectValue("json-flag", new Value(false)); -openFeatureClient.getObjectValue("json-flag", new Value("string")); -openFeatureClient.getObjectValue("json-flag", new Value()); +Value listResult = openFeatureClient.getObjectValue("json-flag", new Value(new ArrayList(Arrays.asList("value1", "value2"))), context); +Value intResult = openFeatureClient.getObjectValue("json-flag", new Value(610), context); +Value boolResult = openFeatureClient.getObjectValue("json-flag", new Value(false), context); +Value stringResult = openFeatureClient.getObjectValue("json-flag", new Value("string"), context); +Value nullResult = openFeatureClient.getObjectValue("json-flag", new Value(), context); ``` However, these are not valid types for the DevCycle SDK, the DevCycle SDK only supports JSON Objects (as `Map`): ```java +MutableContext context = new MutableContext("user-1234"); Map defaultJsonData = new LinkedHashMap<>(); defaultJsonData.put("default", "value"); -openFeatureClient.getObjectValue("json-flag", new Value(Structure.mapToStructure(defaultJsonData))); +Value jsonResult = openFeatureClient.getObjectValue("json-flag", new Value(Structure.mapToStructure(defaultJsonData)), context); + +// Convert the returned Value back to a Map +Map jsonMap = jsonResult.asStructure().asObjectMap(); ``` This is enforced both for both the flag values and the default values supplied to the `getObjectValue()` method. Invalid types will trigger a `dev.openfeature.sdk.exceptions.TypeMismatchError` exception. From 3f359f1df62c7892221d9bf5015a39b4c9cfb605 Mon Sep 17 00:00:00 2001 From: Parth Suthar Date: Thu, 19 Mar 2026 16:29:38 -0400 Subject: [PATCH 2/2] update to add example for json flag eval --- docs/sdk/server-side-sdks/java/java-openfeature.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/sdk/server-side-sdks/java/java-openfeature.md b/docs/sdk/server-side-sdks/java/java-openfeature.md index 8f9567ec..d6fb1fa7 100644 --- a/docs/sdk/server-side-sdks/java/java-openfeature.md +++ b/docs/sdk/server-side-sdks/java/java-openfeature.md @@ -106,6 +106,11 @@ Integer intValue = openFeatureClient.getIntegerValue("integer-flag", 0, context) // Retrieve a double flag value Double doubleValue = openFeatureClient.getDoubleValue("double-flag", 0.0, context); +// Retrieve a json flag value +Map defaultJsonData = new LinkedHashMap<>(); +defaultJsonData.put("default", "value"); +Value jsonResult = openFeatureClient.getObjectValue("json-flag", new Value(Structure.mapToStructure(defaultJsonData)), context); + // Use the returned values in your application logic if (boolValue) { // Feature is enabled @@ -162,7 +167,7 @@ For example the following are all valid default value types to use with OpenFeat ```java MutableContext context = new MutableContext("user-1234"); -// Invalid JSON values for the DevCycle SDK, will return defaults +// Invalid JSON values for the DevCycle SDK, will return the default value with a TYPE_MISMATCH error Value listResult = openFeatureClient.getObjectValue("json-flag", new Value(new ArrayList(Arrays.asList("value1", "value2"))), context); Value intResult = openFeatureClient.getObjectValue("json-flag", new Value(610), context); Value boolResult = openFeatureClient.getObjectValue("json-flag", new Value(false), context); @@ -183,4 +188,4 @@ Value jsonResult = openFeatureClient.getObjectValue("json-flag", new Value(Struc Map jsonMap = jsonResult.asStructure().asObjectMap(); ``` -This is enforced both for both the flag values and the default values supplied to the `getObjectValue()` method. Invalid types will trigger a `dev.openfeature.sdk.exceptions.TypeMismatchError` exception. +This is enforced for both the flag values and the default values supplied to the `getObjectValue()` method. Invalid types will return the default value with a `TYPE_MISMATCH` error code and an `ERROR` reason in the evaluation details.