-
Notifications
You must be signed in to change notification settings - Fork 127
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
ref: refactored events data parsing implementation #231
base: master
Are you sure you want to change the base?
Conversation
…ion implementation
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.
Some serialization concerns, mostly due to Unity ion the case of NewtonsoftJsonDotNet
@@ -7,12 +7,16 @@ internal class ResponseBuilder | |||
private readonly PNConfiguration config; | |||
private readonly IJsonPluggableLibrary jsonLib; | |||
private readonly IPubnubLog pubnubLog; | |||
private readonly NewtonsoftJsonDotNet newtonsoftJsonDotNet; |
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.
There's already a IJsonPluggable reference here, we shouldn't use the concrete implementation because NewtonsoftJsonDotNet breaks in certain Unity build targets
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.
It's safe with that aspect, Since this code is not changing configuration related to serialisation/deserialisation.
NewtonsoftJsonDotNet
is existing custom serialiser library Which is already being used in other parts of the sdk (e.g. PubnubCore class) and got tested already with unity since old versions.
The reason for not using pluggable one, There are some default settings in serialiser(with netwonsoft) and type declarations to make sdk's NewtonsoftJsonDotNet class compatible with unity and other supported targets.
Using pluggable one might leave a chance to break existing behaviour while deserialising the custom user messages.
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.
We currently have NewtonsoftJsonUnity in Unity SDK, which is very similar but uses the Unity version of Newtonsoft library to avoid crashing in IL2CPP build mode (it was a client reported issue a while back), and from what I see we use the DotNet version directly as the default value if no other pluggabel was provided - we definitely can't use it instead of pluggable
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.
updated the implementation, not EventSerializer is using only json pluggable.
for unity compatibility, I saw updates at v6.20.1
also this will make this implementation a bit more unified.
good catch!
public class EventDeserializer | ||
{ | ||
private readonly IJsonPluggableLibrary jsonLibrary; | ||
private readonly NewtonsoftJsonDotNet newtonSoftJsonLibrary; // the default serializer of sdk |
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.
Same here
|
||
private PNPresenceEventResult DeserializePresenceEvent(IDictionary<string, object> jsonFields) | ||
{ | ||
Dictionary<string, object> presenceDicObj = jsonLibrary.ConvertToDictionaryObject(jsonFields["payload"]); |
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.
Any chance the "payload" key won't be there? That goes for the other keys too, do we need TryGetValue-s here?
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.
Agree. I think it's just coding style I followed.
But true, We can avoid those checks.
Updating....
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.
updated for mandatory fields
@@ -23,7 +20,7 @@ public T Deserialize<T>(IDictionary<string, object> json) | |||
var typeInfo = typeof(T); | |||
if (typeInfo.GetTypeInfo().IsGenericType && typeInfo.GetGenericTypeDefinition() == typeof(PNMessageResult<>)) | |||
{ | |||
response = newtonSoftJsonLibrary.DeserializeMessageResultEvent<T>(json); | |||
response = jsonLibrary.DeserializeToObject<T>(json); |
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.
@jakub-grzesiowski updated to json pluggable library
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.
instead jsonDotNet
…ializer dependency
ref(subscribe): events data parsing/deserialisation implementation enhancement
Scope:
Refactor Events data parsing implementation for subscribe responses to avoid major changes in future while updating any event data fields. [e.g Adding custom messageType in message event]
Serialisation library apis changes are out of scope for this change.