@@ -31,14 +31,16 @@ public final class User implements JsonUnknown, JsonSerializable {
3131 /** Username of the user. */
3232 private @ Nullable String username ;
3333
34+ private @ Nullable String segment ;
35+
3436 /** Remote IP address of the user. */
3537 private @ Nullable String ipAddress ;
3638
3739 /**
3840 * Additional arbitrary fields, as stored in the database (and sometimes as sent by clients). All
3941 * data from `self.other` should end up here after store normalization.
4042 */
41- private @ Nullable Map <String , @ NotNull String > other ;
43+ private @ Nullable Map <String , @ NotNull String > data ;
4244
4345 /** unknown fields, only internal usage. */
4446 private @ Nullable Map <String , @ NotNull Object > unknown ;
@@ -50,7 +52,8 @@ public User(final @NotNull User user) {
5052 this .username = user .username ;
5153 this .id = user .id ;
5254 this .ipAddress = user .ipAddress ;
53- this .other = CollectionUtils .newConcurrentHashMap (user .other );
55+ this .segment = user .segment ;
56+ this .data = CollectionUtils .newConcurrentHashMap (user .data );
5457 this .unknown = CollectionUtils .newConcurrentHashMap (user .unknown );
5558 }
5659
@@ -108,6 +111,24 @@ public void setUsername(final @Nullable String username) {
108111 this .username = username ;
109112 }
110113
114+ /**
115+ * Gets the segment of the user.
116+ *
117+ * @return the user segment.
118+ */
119+ public @ Nullable String getSegment () {
120+ return segment ;
121+ }
122+
123+ /**
124+ * Sets the segment of the user.
125+ *
126+ * @param segment the segment.
127+ */
128+ public void setSegment (final @ Nullable String segment ) {
129+ this .segment = segment ;
130+ }
131+
111132 /**
112133 * Gets the IP address of the user.
113134 *
@@ -129,19 +150,43 @@ public void setIpAddress(final @Nullable String ipAddress) {
129150 /**
130151 * Gets other user related data.
131152 *
153+ * @deprecated use {{@link User#getData()}} instead
132154 * @return the other user data.
133155 */
156+ @ Deprecated
157+ @ SuppressWarnings ("InlineMeSuggester" )
134158 public @ Nullable Map <String , @ NotNull String > getOthers () {
135- return other ;
159+ return getData () ;
136160 }
137161
138162 /**
139163 * Sets other user related data.
140164 *
165+ * @deprecated use {{@link User#setData(Map)}} instead
141166 * @param other the other user related data..
142167 */
168+ @ Deprecated
169+ @ SuppressWarnings ("InlineMeSuggester" )
143170 public void setOthers (final @ Nullable Map <String , @ NotNull String > other ) {
144- this .other = CollectionUtils .newConcurrentHashMap (other );
171+ this .setData (other );
172+ }
173+
174+ /**
175+ * Gets additional arbitrary fields of the user.
176+ *
177+ * @return the other user data.
178+ */
179+ public @ Nullable Map <String , @ NotNull String > getData () {
180+ return data ;
181+ }
182+
183+ /**
184+ * Sets additional arbitrary fields of the user.
185+ *
186+ * @param data the other user related data..
187+ */
188+ public void setData (final @ Nullable Map <String , @ NotNull String > data ) {
189+ this .data = CollectionUtils .newConcurrentHashMap (data );
145190 }
146191
147192 // region json
@@ -161,8 +206,10 @@ public static final class JsonKeys {
161206 public static final String EMAIL = "email" ;
162207 public static final String ID = "id" ;
163208 public static final String USERNAME = "username" ;
209+ public static final String SEGMENT = "segment" ;
164210 public static final String IP_ADDRESS = "ip_address" ;
165211 public static final String OTHER = "other" ;
212+ public static final String DATA = "data" ;
166213 }
167214
168215 @ Override
@@ -178,11 +225,14 @@ public void serialize(@NotNull JsonObjectWriter writer, @NotNull ILogger logger)
178225 if (username != null ) {
179226 writer .name (JsonKeys .USERNAME ).value (username );
180227 }
228+ if (segment != null ) {
229+ writer .name (JsonKeys .SEGMENT ).value (segment );
230+ }
181231 if (ipAddress != null ) {
182232 writer .name (JsonKeys .IP_ADDRESS ).value (ipAddress );
183233 }
184- if (other != null ) {
185- writer .name (JsonKeys .OTHER ).value (logger , other );
234+ if (data != null ) {
235+ writer .name (JsonKeys .DATA ).value (logger , data );
186236 }
187237 if (unknown != null ) {
188238 for (String key : unknown .keySet ()) {
@@ -214,14 +264,25 @@ public static final class Deserializer implements JsonDeserializer<User> {
214264 case JsonKeys .USERNAME :
215265 user .username = reader .nextStringOrNull ();
216266 break ;
267+ case JsonKeys .SEGMENT :
268+ user .segment = reader .nextStringOrNull ();
269+ break ;
217270 case JsonKeys .IP_ADDRESS :
218271 user .ipAddress = reader .nextStringOrNull ();
219272 break ;
220- case JsonKeys .OTHER :
221- user .other =
273+ case JsonKeys .DATA :
274+ user .data =
222275 CollectionUtils .newConcurrentHashMap (
223276 (Map <String , String >) reader .nextObjectOrNull ());
224277 break ;
278+ case JsonKeys .OTHER :
279+ // restore `other` from legacy JSON
280+ if (user .data == null || user .data .isEmpty ()) {
281+ user .data =
282+ CollectionUtils .newConcurrentHashMap (
283+ (Map <String , String >) reader .nextObjectOrNull ());
284+ }
285+ break ;
225286 default :
226287 if (unknown == null ) {
227288 unknown = new ConcurrentHashMap <>();
0 commit comments