Class LDUser
- All Implemented Interfaces:
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:
- With
JsonSerialization
. - With Gson, if and only if you configure your
Gson
instance withLDGson
. - With Jackson, if and only if you configure your
ObjectMapper
instance withLDJackson
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Deprecated. -
Constructor Summary
ModifierConstructorDescriptionprotected
LDUser
(LDUser.Builder builder) Deprecated.Deprecated.Create a user with the given key -
Method Summary
Modifier and TypeMethodDescriptionboolean
Deprecated.getAttribute
(UserAttribute attribute) Deprecated.Gets the value of a user attribute, if present.Deprecated.Returns the value of the avatar property for the user, if set.Deprecated.Returns the value of the country property for the user, if set.Deprecated.Returns an enumeration of all custom attribute names that were set for this user.getEmail()
Deprecated.Returns the value of the email property for the user, if set.Deprecated.Returns the value of the first name property for the user, if set.getIp()
Deprecated.Returns the value of the IP property for the user, if set.getKey()
Deprecated.Returns the user's unique key.Deprecated.Returns the value of the last name property for the user, if set.getName()
Deprecated.Returns the value of the full name property for the user, if set.Deprecated.Returns an enumeration of all attributes that were marked private for this user.int
hashCode()
Deprecated.boolean
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.toString()
Deprecated.
-
Constructor Details
-
LDUser
Deprecated. -
LDUser
Deprecated.Create a user with the given key- Parameters:
key
- aString
that uniquely identifies a user
-
-
Method Details
-
getKey
Deprecated.Returns the user's unique key.- Returns:
- the user key as a string
-
getIp
Deprecated.Returns the value of the IP property for the user, if set.- Returns:
- a string or null
-
getCountry
Deprecated.Returns the value of the country property for the user, if set.- Returns:
- a string or null
-
getName
Deprecated.Returns the value of the full name property for the user, if set.- Returns:
- a string or null
-
getFirstName
Deprecated.Returns the value of the first name property for the user, if set.- Returns:
- a string or null
-
getLastName
Deprecated.Returns the value of the last name property for the user, if set.- Returns:
- a string or null
-
getEmail
Deprecated.Returns the value of the email property for the user, if set.- Returns:
- a string or null
-
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
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 returnsLDValue.ofNull()
.- Parameters:
attribute
- the attribute to get- Returns:
- the attribute value or
LDValue.ofNull()
; will never be an actual null reference
-
getCustomAttributes
Deprecated.Returns an enumeration of all custom attribute names that were set for this user.- Returns:
- the custom attribute names
-
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
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
Deprecated. -
hashCode
public int hashCode()Deprecated. -
toString
Deprecated.
-
LDContext
instead.