Skip to content

Commit 4e1af7b

Browse files
committed
[FSSDK-12813] Emit variation_id as JSON null instead of stripping the key
JacksonSerializer sets Include.NON_NULL globally, so any null field is dropped from the wire payload unless overridden at the field level. campaign_id and experiment_id already carried @JsonInclude(ALWAYS); variation_id did not, so once normalization began returning null for non-numeric / empty inputs, the entire variation_id key disappeared from the payload — breaking cross-SDK byte-equivalence (all other SDKs emit explicit JSON null). Added @JsonInclude(ALWAYS) on Decision.variationId, plus a focused serializer test that asserts "variation_id":null is present in the serialized output when the value is null.
1 parent a973d9b commit 4e1af7b

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎core-api/src/main/java/com/optimizely/ab/event/internal/payload/Decision.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class Decision {
2727
@JsonInclude(JsonInclude.Include.ALWAYS)
2828
@JsonProperty("experiment_id")
2929
String experimentId;
30+
@JsonInclude(JsonInclude.Include.ALWAYS)
3031
@JsonProperty("variation_id")
3132
String variationId;
3233
@JsonProperty("is_campaign_holdback")

‎core-api/src/test/java/com/optimizely/ab/event/internal/serializer/JacksonSerializerTest.java‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,51 @@ public void serializeDecisionMetadataWithCmabUuid() throws IOException {
151151
assertTrue("Serialized JSON should contain the UUID value", serialized.contains(cmabUuid));
152152
assertFalse("Serialized JSON must NOT contain 'cmab_u_u_i_d'", serialized.contains("\"cmab_u_u_i_d\""));
153153
}
154+
155+
@Test
156+
public void serializeDecisionWithNullVariationId_emitsExplicitJsonNull() {
157+
// JacksonSerializer sets Include.NON_NULL globally, so fields default to being
158+
// stripped when null. Decision.variation_id must override that with
159+
// @JsonInclude(ALWAYS) so the wire payload carries "variation_id": null instead
160+
// of dropping the key — required for cross-SDK byte-equivalence under FSSDK-12813.
161+
DecisionMetadata metadata = new DecisionMetadata.Builder()
162+
.setFlagKey("test_flag")
163+
.setRuleKey("test_rule")
164+
.setRuleType("holdout")
165+
.setVariationKey("ho_off_key")
166+
.setEnabled(false)
167+
.build();
168+
169+
Decision decision = new Decision.Builder()
170+
.setCampaignId("12345")
171+
.setExperimentId("67890")
172+
.setVariationId(null)
173+
.setIsCampaignHoldback(false)
174+
.setMetadata(metadata)
175+
.build();
176+
177+
Snapshot snapshot = new Snapshot.Builder()
178+
.setDecisions(Collections.singletonList(decision))
179+
.setEvents(Collections.<Event>emptyList())
180+
.build();
181+
182+
Visitor visitor = new Visitor.Builder()
183+
.setVisitorId("visitor123")
184+
.setAttributes(Collections.<Attribute>emptyList())
185+
.setSnapshots(Collections.singletonList(snapshot))
186+
.build();
187+
188+
EventBatch eventBatch = new EventBatch.Builder()
189+
.setAccountId("accountId")
190+
.setProjectId("projectId")
191+
.setRevision("1")
192+
.setVisitors(Collections.singletonList(visitor))
193+
.build();
194+
195+
String serialized = serializer.serialize(eventBatch);
196+
assertTrue(
197+
"variation_id key must be present with explicit null when normalization "
198+
+ "yields null: " + serialized,
199+
serialized.contains("\"variation_id\":null"));
200+
}
154201
}

0 commit comments

Comments
 (0)