@@ -123,7 +123,8 @@ public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defa
123
123
124
124
@ Override
125
125
public ProviderEvaluation <String > getStringEvaluation (String key , String defaultValue , EvaluationContext ctx ) {
126
- ProviderEvaluation <Value > valueProviderEvaluation = getObjectEvaluation (key , new Value (defaultValue ), ctx );
126
+ ProviderEvaluation <Value > valueProviderEvaluation =
127
+ evaluateVariant (String .class , key , new Value (defaultValue ), ctx );
127
128
return ProviderEvaluation .<String >builder ()
128
129
.value (valueProviderEvaluation .getValue ().asString ())
129
130
.variant (valueProviderEvaluation .getVariant ())
@@ -135,7 +136,8 @@ public ProviderEvaluation<String> getStringEvaluation(String key, String default
135
136
136
137
@ Override
137
138
public ProviderEvaluation <Integer > getIntegerEvaluation (String key , Integer defaultValue , EvaluationContext ctx ) {
138
- ProviderEvaluation <Value > valueProviderEvaluation = getObjectEvaluation (key , new Value (defaultValue ), ctx );
139
+ ProviderEvaluation <Value > valueProviderEvaluation =
140
+ evaluateVariant (Integer .class , key , new Value (defaultValue ), ctx );
139
141
Integer value = getIntegerValue (valueProviderEvaluation , defaultValue );
140
142
return ProviderEvaluation .<Integer >builder ()
141
143
.value (value )
@@ -157,7 +159,8 @@ private static Integer getIntegerValue(ProviderEvaluation<Value> valueProviderEv
157
159
158
160
@ Override
159
161
public ProviderEvaluation <Double > getDoubleEvaluation (String key , Double defaultValue , EvaluationContext ctx ) {
160
- ProviderEvaluation <Value > valueProviderEvaluation = getObjectEvaluation (key , new Value (defaultValue ), ctx );
162
+ ProviderEvaluation <Value > valueProviderEvaluation =
163
+ evaluateVariant (Double .class , key , new Value (defaultValue ), ctx );
161
164
Double value = getDoubleValue (valueProviderEvaluation , defaultValue );
162
165
return ProviderEvaluation .<Double >builder ()
163
166
.value (value )
@@ -179,12 +182,18 @@ private static Double getDoubleValue(ProviderEvaluation<Value> valueProviderEval
179
182
180
183
@ Override
181
184
public ProviderEvaluation <Value > getObjectEvaluation (String key , Value defaultValue , EvaluationContext ctx ) {
185
+ return evaluateVariant (Value .class , key , defaultValue , ctx );
186
+ }
187
+
188
+ private <T > ProviderEvaluation <Value > evaluateVariant (Class <T > clazz , String key , Value defaultValue ,
189
+ EvaluationContext ctx ) {
182
190
if (!ProviderState .READY .equals (state )) {
183
191
if (ProviderState .NOT_READY .equals (state )) {
184
192
throw new ProviderNotReadyError (PROVIDER_NOT_YET_INITIALIZED );
185
193
}
186
194
throw new GeneralError (UNKNOWN_ERROR );
187
195
}
196
+
188
197
Map <String , String > contextMap = ContextTransformer .transform (ctx );
189
198
EvaluationRequest request = EvaluationRequest .builder ().namespaceKey (fliptProviderConfig .getNamespace ())
190
199
.flagKey (key ).entityId (ctx .getTargetingKey ()).context (contextMap ).build ();
@@ -209,7 +218,10 @@ public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultVa
209
218
ImmutableMetadata .ImmutableMetadataBuilder flagMetadataBuilder = ImmutableMetadata .builder ();
210
219
if (response .getVariantAttachment () != null && !response .getVariantAttachment ().isEmpty ()) {
211
220
flagMetadataBuilder .addString ("variant-attachment" , response .getVariantAttachment ());
212
- value = new Value (response .getVariantAttachment ());
221
+
222
+ if (clazz .isAssignableFrom (Value .class )) {
223
+ value = new Value (response .getVariantAttachment ());
224
+ }
213
225
}
214
226
215
227
return ProviderEvaluation .<Value >builder ()
0 commit comments