-
-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace user other
with data
#2258
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ public final class User implements JsonUnknown, JsonSerializable { | |
* Additional arbitrary fields, as stored in the database (and sometimes as sent by clients). All | ||
* data from `self.other` should end up here after store normalization. | ||
*/ | ||
private @Nullable Map<String, @NotNull String> other; | ||
private @Nullable Map<String, @NotNull String> data; | ||
|
||
/** unknown fields, only internal usage. */ | ||
private @Nullable Map<String, @NotNull Object> unknown; | ||
|
@@ -53,7 +53,7 @@ public User(final @NotNull User user) { | |
this.id = user.id; | ||
this.ipAddress = user.ipAddress; | ||
this.segment = user.segment; | ||
this.other = CollectionUtils.newConcurrentHashMap(user.other); | ||
this.data = CollectionUtils.newConcurrentHashMap(user.data); | ||
this.unknown = CollectionUtils.newConcurrentHashMap(user.unknown); | ||
} | ||
|
||
|
@@ -150,19 +150,43 @@ public void setIpAddress(final @Nullable String ipAddress) { | |
/** | ||
* Gets other user related data. | ||
* | ||
* @deprecated use getData instead | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use the @link javadocs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
* @return the other user data. | ||
*/ | ||
@Deprecated | ||
@SuppressWarnings("InlineMeSuggester") | ||
public @Nullable Map<String, @NotNull String> getOthers() { | ||
return other; | ||
return getData(); | ||
} | ||
|
||
/** | ||
* Sets other user related data. | ||
* | ||
* @deprecated use setData instead | ||
* @param other the other user related data.. | ||
*/ | ||
@Deprecated | ||
@SuppressWarnings("InlineMeSuggester") | ||
public void setOthers(final @Nullable Map<String, @NotNull String> other) { | ||
this.other = CollectionUtils.newConcurrentHashMap(other); | ||
this.setData(other); | ||
} | ||
|
||
/** | ||
* Gets additional arbitrary fields of the user. | ||
* | ||
* @return the other user data. | ||
*/ | ||
public @Nullable Map<String, @NotNull String> getData() { | ||
return data; | ||
} | ||
|
||
/** | ||
* Sets additional arbitrary fields of the user. | ||
* | ||
* @param data the other user related data.. | ||
*/ | ||
public void setData(final @Nullable Map<String, @NotNull String> data) { | ||
this.data = CollectionUtils.newConcurrentHashMap(data); | ||
} | ||
|
||
// region json | ||
|
@@ -185,6 +209,7 @@ public static final class JsonKeys { | |
public static final String SEGMENT = "segment"; | ||
public static final String IP_ADDRESS = "ip_address"; | ||
public static final String OTHER = "other"; | ||
public static final String DATA = "data"; | ||
} | ||
|
||
@Override | ||
|
@@ -206,8 +231,8 @@ public void serialize(@NotNull JsonObjectWriter writer, @NotNull ILogger logger) | |
if (ipAddress != null) { | ||
writer.name(JsonKeys.IP_ADDRESS).value(ipAddress); | ||
} | ||
if (other != null) { | ||
writer.name(JsonKeys.OTHER).value(logger, other); | ||
if (data != null) { | ||
writer.name(JsonKeys.DATA).value(logger, data); | ||
} | ||
if (unknown != null) { | ||
for (String key : unknown.keySet()) { | ||
|
@@ -245,11 +270,18 @@ public static final class Deserializer implements JsonDeserializer<User> { | |
case JsonKeys.IP_ADDRESS: | ||
user.ipAddress = reader.nextStringOrNull(); | ||
break; | ||
case JsonKeys.OTHER: | ||
user.other = | ||
case JsonKeys.DATA: | ||
user.data = | ||
CollectionUtils.newConcurrentHashMap( | ||
(Map<String, String>) reader.nextObjectOrNull()); | ||
break; | ||
case JsonKeys.OTHER: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
if (user.data == null || user.data.isEmpty()) { | ||
user.data = | ||
CollectionUtils.newConcurrentHashMap( | ||
(Map<String, String>) reader.nextObjectOrNull()); | ||
} | ||
break; | ||
default: | ||
if (unknown == null) { | ||
unknown = new ConcurrentHashMap<>(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,15 @@ class UserSerializationTest { | |
assertEquals(expectedJson, actualJson) | ||
} | ||
|
||
@Test | ||
fun deserializeLegacy() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 馃憤 for adding a test for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use backticks and call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
val inputJson = sanitizedFile("json/user_legacy.json") | ||
val expectedJson = sanitizedFile("json/user.json") | ||
val actual = deserialize(inputJson) | ||
val actualJson = serialize(actual) | ||
assertEquals(expectedJson, actualJson) | ||
} | ||
|
||
// Helper | ||
|
||
private fun sanitizedFile(path: String): String { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"email": "c4d61c1b-c144-431e-868f-37a46be5e5f2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding this 馃憦 |
||
"id": "efb2084b-1871-4b59-8897-b4bd9f196a01", | ||
"username": "60c05dff-7140-4d94-9a61-c9cdd9ca9b96", | ||
"ip_address": "51d22b77-f663-4dbe-8103-8b749d1d9a48", | ||
"other": | ||
{ | ||
"dc2813d0-0f66-4a3f-a995-71268f61a8fa": "991659ad-7c59-4dd3-bb89-0bd5c74014bd" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR title and changelog seem to be off, this is not about the
user.segment
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow good catch thanks! Not sure how that happened. Guess I just rely on the auto generated title too much and in this case it used the title from the PR I want to merge into.