|
20 | 20 | import com.google.gson.JsonDeserializationContext; |
21 | 21 | import com.google.gson.JsonElement; |
22 | 22 | import com.google.gson.JsonObject; |
| 23 | +import com.google.gson.JsonParseException; |
23 | 24 | import com.google.gson.reflect.TypeToken; |
| 25 | +import com.optimizely.ab.bucketing.DecisionService; |
24 | 26 | import com.optimizely.ab.config.Experiment; |
25 | 27 | import com.optimizely.ab.config.Experiment.ExperimentStatus; |
26 | 28 | import com.optimizely.ab.config.FeatureFlag; |
27 | 29 | import com.optimizely.ab.config.LiveVariable; |
28 | 30 | import com.optimizely.ab.config.LiveVariableUsageInstance; |
29 | 31 | import com.optimizely.ab.config.TrafficAllocation; |
30 | 32 | import com.optimizely.ab.config.Variation; |
| 33 | +import org.slf4j.Logger; |
| 34 | +import org.slf4j.LoggerFactory; |
31 | 35 |
|
32 | 36 | import java.lang.reflect.Type; |
33 | 37 | import java.util.ArrayList; |
|
38 | 42 |
|
39 | 43 | final class GsonHelpers { |
40 | 44 |
|
| 45 | + private static final Logger logger = LoggerFactory.getLogger(DecisionService.class); |
| 46 | + |
41 | 47 | private static List<Variation> parseVariations(JsonArray variationJson, JsonDeserializationContext context) { |
42 | 48 | List<Variation> variations = new ArrayList<Variation>(variationJson.size()); |
43 | 49 | for (Object obj : variationJson) { |
@@ -127,9 +133,17 @@ static FeatureFlag parseFeatureFlag(JsonObject featureFlagJson, JsonDeserializat |
127 | 133 | experimentIds.add(experimentIdObj.getAsString()); |
128 | 134 | } |
129 | 135 |
|
130 | | - Type liveVariableType = new TypeToken<List<LiveVariable>>() {}.getType(); |
131 | | - List<LiveVariable> liveVariables = context.deserialize(featureFlagJson.getAsJsonArray("variables"), |
132 | | - liveVariableType); |
| 136 | + List<LiveVariable> liveVariables = new ArrayList<LiveVariable>(); |
| 137 | + try { |
| 138 | + Type liveVariableType = new TypeToken<List<LiveVariable>>() { |
| 139 | + }.getType(); |
| 140 | + liveVariables = context.deserialize(featureFlagJson.getAsJsonArray("variables"), |
| 141 | + liveVariableType); |
| 142 | + } |
| 143 | + catch (JsonParseException exception) { |
| 144 | + logger.warn("Unable to parse variables for feature \"" + key |
| 145 | + + "\". JsonParseException: " + exception); |
| 146 | + } |
133 | 147 |
|
134 | 148 | return new FeatureFlag( |
135 | 149 | id, |
|
0 commit comments