Feature Variants
The Java SDK assigns feature variants locally from the definitions catalog.
There is no separate evaluated-variants-signed fetch and no enableVariants
toggle.
How it works
- The SDK downloads
definitions/definitions-signedas usual. - Each feature may include
variantsandallocation(user, group, percentile, defaults, optional seed). isEnabledcontinues to evaluate filters locally.getVariant/getVariantValuerun the catalog allocator for the current targeting context (userId+groups).
Assignment order when the feature is enabled: user → group → percentile →
defaultWhenEnabled. When the feature is disabled, only defaultWhenDisabled
applies. Percentile hashing uses SHA-256 over {userId}\n{hint} (optional
allocation seed, otherwise allocation\n{featureKey}).
Reading a variant
TogglyConfig config = TogglyConfig.builder()
.appKey("YOUR_APP_KEY")
.environment("Production")
.identity("user-42") // used as targeting userId when set
.build();
try (TogglyClient client = new TogglyClient(config)) {
client.refresh();
VariantResult variant = client.getVariant("checkout-experiment");
if (variant != null) {
System.out.println("Assigned to: " + variant.getName());
Object payload = variant.getConfigurationValue();
}
Object value = client.getVariantValue("checkout-experiment");
}
Override targeting per call when your language API exposes it (user id + groups) so each request can use its own identity.
getVariant returns null when no variant is assigned (no allocation match,
missing catalog fields, or unknown feature key).
VariantResult exposes:
| Method | Description |
|---|---|
getName() | Assigned variant name |
getConfigurationValue() | Optional per-variant payload |
Status override
A variant may set statusOverride to force the feature effective enabled or
disabled after assignment. Documented on the wire as part of each variant
definition.
Not the same as telemetry's variant label
recordUsage / recordView accept an optional variant label for
telemetry. That does not assign a feature variant. Use getVariant for
assignment.