LDContext
instead.@Deprecated public class LDUser extends java.lang.Object implements JsonSerializable
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:
JsonSerialization
.
Gson
instance with
LDGson
.
ObjectMapper
instance with
LDJackson
.
Modifier and Type | Class and Description |
---|---|
static class |
LDUser.Builder
Deprecated.
use
ContextBuilder or ContextMultiBuilder instead via LDContext.builder(String) . |
Modifier | Constructor and Description |
---|---|
protected |
LDUser(LDUser.Builder builder)
Deprecated.
|
|
LDUser(java.lang.String key)
Deprecated.
Create a user with the given key
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o)
Deprecated.
|
LDValue |
getAttribute(UserAttribute attribute)
Deprecated.
Gets the value of a user attribute, if present.
|
java.lang.String |
getAvatar()
Deprecated.
Returns the value of the avatar property for the user, if set.
|
java.lang.String |
getCountry()
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.String |
getEmail()
Deprecated.
Returns the value of the email property for the user, if set.
|
java.lang.String |
getFirstName()
Deprecated.
Returns the value of the first name property for the user, if set.
|
java.lang.String |
getIp()
Deprecated.
Returns the value of the IP property for the user, if set.
|
java.lang.String |
getKey()
Deprecated.
Returns the user's unique key.
|
java.lang.String |
getLastName()
Deprecated.
Returns the value of the last name property for the user, if set.
|
java.lang.String |
getName()
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.
|
int |
hashCode()
Deprecated.
|
boolean |
isAnonymous()
Deprecated.
Returns true if this user was marked anonymous.
|
boolean |
isAttributePrivate(UserAttribute attribute)
Deprecated.
Tests whether an attribute has been marked private for this user.
|
java.lang.String |
toString()
Deprecated.
|
protected LDUser(LDUser.Builder builder)
public LDUser(java.lang.String key)
key
- a String
that uniquely identifies a userpublic java.lang.String getKey()
public java.lang.String getIp()
public java.lang.String getCountry()
public java.lang.String getName()
public java.lang.String getFirstName()
public java.lang.String getLastName()
public java.lang.String getEmail()
public java.lang.String getAvatar()
public boolean isAnonymous()
public LDValue getAttribute(UserAttribute attribute)
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()
.
attribute
- the attribute to getLDValue.ofNull()
; will never be an actual null referencepublic java.lang.Iterable<UserAttribute> getCustomAttributes()
public java.lang.Iterable<UserAttribute> getPrivateAttributes()
This does not include any attributes that were globally marked private in your SDK configuration.
public boolean isAttributePrivate(UserAttribute attribute)
attribute
- a built-in or custom attributepublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object