Class LDUser
- java.lang.Object
-
- com.launchdarkly.sdk.LDUser
-
- All Implemented Interfaces:
JsonSerializable
@Deprecated public class LDUser extends java.lang.Object implements JsonSerializable
Deprecated.useLDContextinstead.Attributes of a user for whom you are evaluating feature flags.LDUsercontains 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
LDContexttype. An LDUser is equivalent to an individualLDContextthat has aContextKindofContextKind.DEFAULT("user"); it also has more constraints on attribute values than LDContext does (for instance, built-in attributes such asLDUser.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)andLDUser.Builder.country(String)) and custom attributes. The built-in attributes have specific allowed value types; also, two of them (nameandanonymous) 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.
LDUsercan be converted to and from JSON in any of these ways:- With
JsonSerialization. - With Gson, if and only if you configure your
Gsoninstance withLDGson. - With Jackson, if and only if you configure your
ObjectMapperinstance withLDJackson.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLDUser.BuilderDeprecated.
-
Constructor Summary
Constructors Modifier Constructor Description protectedLDUser(LDUser.Builder builder)Deprecated.LDUser(java.lang.String key)Deprecated.Create a user with the given key
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanequals(java.lang.Object o)Deprecated.LDValuegetAttribute(UserAttribute attribute)Deprecated.Gets the value of a user attribute, if present.java.lang.StringgetAvatar()Deprecated.Returns the value of the avatar property for the user, if set.java.lang.StringgetCountry()Deprecated.Returns the value of the country property for the user, if set.java.lang.Iterable<UserAttribute>getCustomAttributes()Deprecated.Returns an enumeration of all custom attribute names that were set for this user.java.lang.StringgetEmail()Deprecated.Returns the value of the email property for the user, if set.java.lang.StringgetFirstName()Deprecated.Returns the value of the first name property for the user, if set.java.lang.StringgetIp()Deprecated.Returns the value of the IP property for the user, if set.java.lang.StringgetKey()Deprecated.Returns the user's unique key.java.lang.StringgetLastName()Deprecated.Returns the value of the last name property for the user, if set.java.lang.StringgetName()Deprecated.Returns the value of the full name property for the user, if set.java.lang.Iterable<UserAttribute>getPrivateAttributes()Deprecated.Returns an enumeration of all attributes that were marked private for this user.inthashCode()Deprecated.booleanisAnonymous()Deprecated.Returns true if this user was marked anonymous.booleanisAttributePrivate(UserAttribute attribute)Deprecated.Tests whether an attribute has been marked private for this user.java.lang.StringtoString()Deprecated.
-
-
-
Constructor Detail
-
LDUser
protected LDUser(LDUser.Builder builder)
Deprecated.
-
LDUser
public LDUser(java.lang.String key)
Deprecated.Create a user with the given key- Parameters:
key- aStringthat uniquely identifies a user
-
-
Method Detail
-
getKey
public java.lang.String getKey()
Deprecated.Returns the user's unique key.- Returns:
- the user key as a string
-
getIp
public java.lang.String getIp()
Deprecated.Returns the value of the IP property for the user, if set.- Returns:
- a string or null
-
getCountry
public java.lang.String getCountry()
Deprecated.Returns the value of the country property for the user, if set.- Returns:
- a string or null
-
getName
public java.lang.String getName()
Deprecated.Returns the value of the full name property for the user, if set.- Returns:
- a string or null
-
getFirstName
public java.lang.String getFirstName()
Deprecated.Returns the value of the first name property for the user, if set.- Returns:
- a string or null
-
getLastName
public java.lang.String getLastName()
Deprecated.Returns the value of the last name property for the user, if set.- Returns:
- a string or null
-
getEmail
public java.lang.String getEmail()
Deprecated.Returns the value of the email property for the user, if set.- Returns:
- a string or null
-
getAvatar
public java.lang.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
LDValuetype, which can have any type that is supported in JSON. If the attribute does not exist, it returnsLDValue.ofNull().- Parameters:
attribute- the attribute to get- Returns:
- the attribute value or
LDValue.ofNull(); will never be an actual null reference
-
getCustomAttributes
public java.lang.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 java.lang.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(java.lang.Object o)
Deprecated.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Deprecated.- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
Deprecated.- Overrides:
toStringin classjava.lang.Object
-
-