Class EvaluationDetail<T>

java.lang.Object
com.launchdarkly.sdk.EvaluationDetail<T>
Type Parameters:
T - the type of the wrapped value
All Implemented Interfaces:
JsonSerializable

public final class EvaluationDetail<T> extends Object implements JsonSerializable
An object returned by the SDK's "variation detail" methods such as boolVariationDetail, combining the result of a flag evaluation with an explanation of how it was calculated.

EvaluationReason can be converted to and from JSON in any of these ways:

  1. With JsonSerialization.
  2. With Gson, if and only if you configure your Gson instance with LDGson.
  3. With Jackson, if and only if you configure your ObjectMapper instance with LDJackson.
Note: There is currently a limitation regarding deserialization for generic types. If you use Gson, you must pass a `TypeToken` to specify the runtime type of EvaluationDetail<T>, or else it will assume that `T` is `LDValue`. If you use either JsonSerialization or Jackson, there is no way to specify the runtime type and you will always get an EvaluationDetail<LDValue>. That is only for deserialization; serialization will always use the correct value type.
  • Field Details

    • NO_VARIATION

      public static final int NO_VARIATION
      If getVariationIndex() is equal to this constant, it means no variation was chosen (evaluation failed and returned a default value).
      See Also:
  • Method Details

    • fromValue

      public static <T> EvaluationDetail<T> fromValue(T value, int variationIndex, EvaluationReason reason)
      Factory method for an arbitrary value.
      Type Parameters:
      T - the type of the value
      Parameters:
      value - a value of the desired type
      variationIndex - a variation index, or NO_VARIATION (any negative number will be changed to NO_VARIATION)
      reason - an EvaluationReason (should not be null)
      Returns:
      an EvaluationDetail
    • error

      public static EvaluationDetail<LDValue> error(EvaluationReason.ErrorKind errorKind, LDValue defaultValue)
      Shortcut for creating an instance with an error result.
      Parameters:
      errorKind - the type of error
      defaultValue - the application default value
      Returns:
      an EvaluationDetail
    • getReason

      public EvaluationReason getReason()
      An object describing the main factor that influenced the flag evaluation value.
      Returns:
      an EvaluationReason
    • getVariationIndex

      public int getVariationIndex()
      The index of the returned value within the flag's list of variations, e.g. 0 for the first variation, or NO_VARIATION.
      Returns:
      the variation index if applicable
    • getValue

      public T getValue()
      The result of the flag evaluation. This will be either one of the flag's variations or the default value that was passed to the variation method.
      Returns:
      the flag value
    • isDefaultValue

      public boolean isDefaultValue()
      Returns true if the flag evaluation returned the default value, rather than one of the flag's variations. If so, getVariationIndex() will be NO_VARIATION.
      Returns:
      true if this is the default value
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a simple string representation of this instance.

      This is a convenience method for debugging and any other use cases where a human-readable string is helpful. The exact format of the string is subject to change; if you need to make programmatic decisions based on the object's properties, use other methods like getValue().

      Overrides:
      toString in class Object