Class LDUser

java.lang.Object
com.launchdarkly.sdk.LDUser
All Implemented Interfaces:
JsonSerializable

@Deprecated public class LDUser extends Object implements JsonSerializable
Deprecated.
use LDContext instead.
Attributes of a user for whom you are evaluating feature flags.

LDUser contains any user-specific properties that may be used in feature flag configurations to produce different flag variations for different users. You may define these properties however you wish.

LDUser supports only a subset of the behaviors that are available with the newer LDContext type. An LDUser is equivalent to an individual LDContext that has a ContextKind of ContextKind.DEFAULT ("user"); it also has more constraints on attribute values than LDContext does (for instance, built-in attributes such as LDUser.Builder.email(String) can only have string values). Older LaunchDarkly SDKs only had the LDUser model, and the LDUser type has been retained for backward compatibility, but it may be removed in a future SDK version; also, the SDK will always convert an LDUser to an LDContext internally, which has some overhead. Therefore, developers are recommended to migrate toward using LDContext.

The only mandatory property of LDUser is the key, which must uniquely identify each user. For authenticated users, this may be a username or e-mail address. For anonymous users, this could be an IP address or session ID.

Besides the mandatory key, LDUser supports two kinds of optional attributes: built-in attributes (e.g. LDUser.Builder.name(String) and LDUser.Builder.country(String)) and custom attributes. The built-in attributes have specific allowed value types; also, two of them (name and anonymous) have special meanings in LaunchDarkly. Custom attributes have flexible value types, and can have any names that do not conflict with built-in attributes.

Both built-in attributes and custom attributes can be referenced in targeting rules, and are included in analytics data.

Instances of LDUser are immutable once created. They can be created with the constructor, or using a builder pattern with LDUser.Builder.

LaunchDarkly defines a standard JSON encoding for user objects, used by the JavaScript SDK and also in analytics events. LDUser 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.
  • Constructor Details

    • LDUser

      protected LDUser(LDUser.Builder builder)
      Deprecated.
    • LDUser

      public LDUser(String key)
      Deprecated.
      Create a user with the given key
      Parameters:
      key - a String that uniquely identifies a user
  • Method Details

    • getKey

      public String getKey()
      Deprecated.
      Returns the user's unique key.
      Returns:
      the user key as a string
    • getIp

      public String getIp()
      Deprecated.
      Returns the value of the IP property for the user, if set.
      Returns:
      a string or null
    • getCountry

      public String getCountry()
      Deprecated.
      Returns the value of the country property for the user, if set.
      Returns:
      a string or null
    • getName

      public String getName()
      Deprecated.
      Returns the value of the full name property for the user, if set.
      Returns:
      a string or null
    • getFirstName

      public String getFirstName()
      Deprecated.
      Returns the value of the first name property for the user, if set.
      Returns:
      a string or null
    • getLastName

      public String getLastName()
      Deprecated.
      Returns the value of the last name property for the user, if set.
      Returns:
      a string or null
    • getEmail

      public String getEmail()
      Deprecated.
      Returns the value of the email property for the user, if set.
      Returns:
      a string or null
    • getAvatar

      public String getAvatar()
      Deprecated.
      Returns the value of the avatar property for the user, if set.
      Returns:
      a string or null
    • isAnonymous

      public boolean isAnonymous()
      Deprecated.
      Returns true if this user was marked anonymous.
      Returns:
      true for an anonymous user
    • getAttribute

      public LDValue getAttribute(UserAttribute attribute)
      Deprecated.
      Gets the value of a user attribute, if present.

      This can be either a built-in attribute or a custom one. It returns the value using the LDValue type, which can have any type that is supported in JSON. If the attribute does not exist, it returns LDValue.ofNull().

      Parameters:
      attribute - the attribute to get
      Returns:
      the attribute value or LDValue.ofNull(); will never be an actual null reference
    • getCustomAttributes

      public Iterable<UserAttribute> getCustomAttributes()
      Deprecated.
      Returns an enumeration of all custom attribute names that were set for this user.
      Returns:
      the custom attribute names
    • getPrivateAttributes

      public Iterable<UserAttribute> getPrivateAttributes()
      Deprecated.
      Returns an enumeration of all attributes that were marked private for this user.

      This does not include any attributes that were globally marked private in your SDK configuration.

      Returns:
      the names of private attributes for this user
    • isAttributePrivate

      public boolean isAttributePrivate(UserAttribute attribute)
      Deprecated.
      Tests whether an attribute has been marked private for this user.
      Parameters:
      attribute - a built-in or custom attribute
      Returns:
      true if the attribute was marked private on a per-user level
    • equals

      public boolean equals(Object o)
      Deprecated.
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Deprecated.
      Overrides:
      toString in class Object