Package growthbook.sdk.java.evaluators
Class PayloadReducer
java.lang.Object
growthbook.sdk.java.evaluators.PayloadReducer
Shrinks a features payload for a user whose attributes are only partly known, e.g. on a server
bootstrapping a client SDK. The reduced payload evaluates the same as the full one for anyone
who agrees with the known attributes.
Stateless and safe for concurrent use. Inputs are never modified.
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.gson.JsonElementpruneCondition(com.google.gson.JsonObject attributes, com.google.gson.JsonObject condition, com.google.gson.JsonObject savedGroups) Partially evaluates a condition when only some attributes are known.static com.google.gson.JsonObjectreducePayload(com.google.gson.JsonObject payload, com.google.gson.JsonObject attributes, ReducePayloadOptions options) Reduces a decrypted features payload for one user.
-
Method Details
-
pruneCondition
public static com.google.gson.JsonElement pruneCondition(@Nullable com.google.gson.JsonObject attributes, com.google.gson.JsonObject condition, @Nullable com.google.gson.JsonObject savedGroups) Partially evaluates a condition when only some attributes are known. Attributes missing fromattributesare unknown, and so is any nested (dotted) path.- Parameters:
attributes- the known attributescondition- the condition to prunesavedGroups- the payload's saved groups, ornullfor none- Returns:
- a boolean
JsonPrimitiveonce the result can't depend on unknown attributes, otherwise aJsonObjectwith the condition minus every branch that is already decided
-
reducePayload
public static com.google.gson.JsonObject reducePayload(com.google.gson.JsonObject payload, @Nullable com.google.gson.JsonObject attributes, @Nullable ReducePayloadOptions options) Reduces a decrypted features payload for one user.Features and auto experiments are kept or dropped by the
include/excludefilters on their project, tag and custom-field metadata. Rule and experiment conditions are reduced withpruneCondition(com.google.gson.JsonObject, com.google.gson.JsonObject, com.google.gson.JsonObject): a condition that always passes is removed, and one that never passes becomes{"$not": {}}(a force rule's value becomesnull). The prerequisites of kept features stay, unlessReducePayloadOptions.Prerequisites.FILTERis set. Saved groups and contextual bandits nothing references any more are dropped.- Parameters:
payload- the decrypted payload (features,experiments,savedGroups,contextualBandits, ...)attributes- the known attributes, global and per-user merged;nullfor noneoptions- filters and prerequisite handling;nullfor defaults- Returns:
- a new payload: the input's other keys, with
features,experimentsandsavedGroupsreduced, andcontextualBanditsreduced when the input had them
-