Class PayloadReducer

java.lang.Object
growthbook.sdk.java.evaluators.PayloadReducer

public final class PayloadReducer extends Object
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 Type
    Method
    Description
    static com.google.gson.JsonElement
    pruneCondition(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.JsonObject
    reducePayload(com.google.gson.JsonObject payload, com.google.gson.JsonObject attributes, ReducePayloadOptions options)
    Reduces a decrypted features payload for one user.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 from attributes are unknown, and so is any nested (dotted) path.
      Parameters:
      attributes - the known attributes
      condition - the condition to prune
      savedGroups - the payload's saved groups, or null for none
      Returns:
      a boolean JsonPrimitive once the result can't depend on unknown attributes, otherwise a JsonObject with 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/exclude filters on their project, tag and custom-field metadata. Rule and experiment conditions are reduced with pruneCondition(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 becomes null). The prerequisites of kept features stay, unless ReducePayloadOptions.Prerequisites.FILTER is 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; null for none
      options - filters and prerequisite handling; null for defaults
      Returns:
      a new payload: the input's other keys, with features, experiments and savedGroups reduced, and contextualBandits reduced when the input had them