-
Notifications
You must be signed in to change notification settings - Fork 55
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
Exposing two new APIs trySerialize() and tryDeserialize() which do not fail fast on any error occurrence. Instead, they return maximum possible serializable/deserializable object/array and all errors. #103
base: master
Are you sure you want to change the base?
Conversation
Thank you for this interesting approach. It's a good idea to add a method to try deserialization and serialization. I didn't have time yet to have a deep look. How do you create an instance of a class partially? I think the value object returned should be rather
(if the property was missing in the JSON, use the default value). What was your motivation to change the return values of the existing deserialize/serialize methods? I don't think we should change them because this will mean a breaking change for all developers using the library. |
Thanks for immediate feedback on the PR :) (1) What was your motivation to change the return values of the existing deserialize/serialize methods? I have changed the return values of only serializeObject()/serializeArray() and deserializeObject()/deserializeArray() methods. The wrapper methods, serialize() & deserialize(), are untouched. Their functionality remains the same. My assumption was that any user would use wrapper methods rather than specific methods for array or object.Now after looking at the documentation examples, I realise that users might be using specific deserialize/serialize methods depending on array or objects. (2) How do you create an instance of a class partially?
Looking forward to your code review. I will be happy to contribute if you ask me to address anything or may be changing the implementation to take into account your above mentioned concerns :) If you feel that we should have this kind of methods (trySerialize() and tryDeserialize()) with all errors, then please let me know. |
…isting developer experience does not break
Hello Andreas. Updated the PR to retain existing serialize/deserialize methods. Now, there is no breaking experience. |
Added two new APIs:
(a)
trySerialize<T>(data: T | T[]): {value: any | any[], error: any} { ... }
This method tries to serialize input data and returns value: maximum possible serializable array/object and error: errors found in serialization.
(b)
tryDeserialize<T>(json: any, classReference: { new(): T }): {value: any, error: any} { ... }
This method tries to deserialize input json and returns value: maximum possible deserializable array/object and error: errors found in deserialization.
Example usage:-
Snake & Human Class:-
Input Json to be deserialized to Snake Type:-
Error Object Returned :-
Value Object Returned :-