public class LDUser extends java.lang.Object implements JsonSerializable
The only mandatory property is the key
, which must uniquely identify each user; this could be a username
or email address for authenticated users, or a session ID for anonymous users. All other built-in properties are
optional. You may also define custom properties with arbitrary names and values.
For a fuller description of user attributes and how they can be referenced in feature flag rules, see the reference guides on Setting user attributes and Targeting users.
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
|
Modifier | Constructor and Description |
---|---|
protected |
LDUser(LDUser.Builder builder) |
|
LDUser(java.lang.String key)
Create a user with the given key
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object o) |
LDValue |
getAttribute(UserAttribute attribute)
Gets the value of a user attribute, if present.
|
java.lang.String |
getAvatar()
Returns the value of the avatar property for the user, if set.
|
java.lang.String |
getCountry()
Returns the value of the country property for the user, if set.
|
java.lang.Iterable<UserAttribute> |
getCustomAttributes()
Returns an enumeration of all custom attribute names that were set for this user.
|
java.lang.String |
getEmail()
Returns the value of the email property for the user, if set.
|
java.lang.String |
getFirstName()
Returns the value of the first name property for the user, if set.
|
java.lang.String |
getIp()
Returns the value of the IP property for the user, if set.
|
java.lang.String |
getKey()
Returns the user's unique key.
|
java.lang.String |
getLastName()
Returns the value of the last name property for the user, if set.
|
java.lang.String |
getName()
Returns the value of the full name property for the user, if set.
|
java.lang.Iterable<UserAttribute> |
getPrivateAttributes()
Returns an enumeration of all attributes that were marked private for this user.
|
java.lang.String |
getSecondary()
Returns the value of the secondary key property for the user, if set.
|
int |
hashCode() |
boolean |
isAnonymous()
Returns true if this user was marked anonymous.
|
boolean |
isAttributePrivate(UserAttribute attribute)
Tests whether an attribute has been marked private for this user.
|
java.lang.String |
toString() |
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 getSecondary()
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