-
Notifications
You must be signed in to change notification settings - Fork 76
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow arbitrary extra data in API objects that support this loose format #104
Conversation
99f68b1
to
0cc0199
Compare
This is so weird. The test that is failing on the push should ALWAYS be failing but it passes because the JVM is pretty fast. We are comparing two different calls to the current system time for equality, so I'll fix that. |
@@ -25,6 +25,8 @@ | |||
|
|||
public class Factory { | |||
|
|||
private static final long CURRENT_TIME = System.currentTimeMillis(); |
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.
Good catch!
private Person(Builder builder) { | ||
this.id = builder.id; | ||
this.username = builder.username; | ||
this.email = builder.email; | ||
this.metadata = builder.metadata != null ? unmodifiableMap(builder.metadata) : null; |
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.
Might not be a big deal, but unmodifiableMap()
doesn't guarantee that the map is immutable. So this change actually changes Person from an immutable object to a mutable one (though it can only be mutated by mutating the map passed to the builder).
FWIW.
@rokob is there anything I can do to help here? I am guessing you're wanting to solve the NPath complexity warnings that Codacy raised. If that's true, I can work on a solution. |
In the API docs some of the elements in the payload body support arbitrary extra data with a comment that starts like
// Can contain any arbitrary keys.
. This PR adds back the ability to include this extra data with the various objects that the API understands, namely:Server
,Message
,Request
.Client
already supports this. Additionally, the docs don't mention it but we have always supported arbitrary extra data withPerson
so this adds that capacity as well.The general form is to use the Builder for each type and to pass in a
Map<String, Object>
to themetadata
function. This map will get merged into the final JSON for that object before the standard keys are added. That means that keys that are standard such asbody
for theMessage
type will be overwritten if they exist in this metadata object. See the tests added herein for examples of this behaviour.Fixes #86