You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So the reason for this request is as follows. Picture you have a class that has a few properties, you have to serialise and de-serialise when doing server calls, all is perfect, network calls are fine ect etc.
Now the issue comes in when you start having multiple classes with loads of properties, and theses classes reference other classes that have loads of properties. When you are serialising the classes now the json object returned starts getting rather large, which causes the network requests to become rather large also, and user experience starts going down the drain.
What I am requesting is a way to make the serialisation remove properties that are equal to their default values, consider the following class:
When serialising these items currently both of them will have 4 properties in the serialised object, but if we drop the values that are equal to the defaults, then car1 would only have 2 properties in the serialised object,
While in this scenario this is not a lot, there are other applications that can benefit a lot from something like this.
I do understand that this would not be valid for lots of applications, and feel that it is more of a niche case, but this would help a lot in the overall experience in the project that I a busy with, as I am using json2typescript for serialisation and de-serialisation, so there should also not be any data loss.
The text was updated successfully, but these errors were encountered:
Well I'm guessing there are 3 ways to go; either add a new serialize method that can do this, or add another parameter to the existing serialize method that can toggle this functionality on or off, or as you suggested as a setting on the instance.
Have you given any thought as to which method would be the best to use? I would like to look at this issue and submit a pull, but would like your input on the best way to do this.
I suggest that we introduce a new flag for serialization mode. When set, the serialization compares a given instance to a new instance and omits equal values.
There is still discussion going on in a PR how we shall handle different scenarios of serialization with null/undefined, so I am not sure if we should wait for that and include this flag there.
Hey guys,
So the reason for this request is as follows. Picture you have a class that has a few properties, you have to serialise and de-serialise when doing server calls, all is perfect, network calls are fine ect etc.
Now the issue comes in when you start having multiple classes with loads of properties, and theses classes reference other classes that have loads of properties. When you are serialising the classes now the json object returned starts getting rather large, which causes the network requests to become rather large also, and user experience starts going down the drain.
What I am requesting is a way to make the serialisation remove properties that are equal to their default values, consider the following class:
Now consider the following two objects:
When serialising these items currently both of them will have 4 properties in the serialised object, but if we drop the values that are equal to the defaults, then
car1
would only have 2 properties in the serialised object,and
car2
would only have 3 properties.While in this scenario this is not a lot, there are other applications that can benefit a lot from something like this.
I do understand that this would not be valid for lots of applications, and feel that it is more of a niche case, but this would help a lot in the overall experience in the project that I a busy with, as I am using json2typescript for serialisation and de-serialisation, so there should also not be any data loss.
The text was updated successfully, but these errors were encountered: