mgholam / fastJSON

Smallest, fastest polymorphic JSON serializer
https://www.codeproject.com/Articles/159450/fastJSON-Smallest-Fastest-Polymorphic-JSON-Seriali
MIT License
479 stars 147 forks source link

Custom JSONParameters base on global JSON.Parameters #100

Closed alesrazym closed 5 years ago

alesrazym commented 5 years ago

I'd like to have option to (de)serialize some data with different JSONParameters, based on global JSON.Parameters.

JSON.DeepCopy<JSONParameters>() fails and JSONParameters.MakeCopy() is not public. Is there any other solution? Is it possible to make JSONParameters.MakeCopy() public?

mgholam commented 5 years ago

And how will making JSONParameters.MakeCopy() public help?

alesrazym commented 5 years ago

I don't want to change global JSON.Parameters itself, used widely in JSON.ToJSON(object), but make a copy to change just a subset of parameters and use it in JSON.ToJSON(object, JSON.Parameters). For example I do not want to serialize type in global settings, but do want for some special case.

If I can make copy, then I can safely change one parameter withou knowing the others settings.

mgholam commented 5 years ago

You can easily do that right now :

var jp1 = new JSONParameters { UseExtensions = false }; // everything else as default
var jp2 = new JSONParameters { UseFastGuid = false };  
alesrazym commented 5 years ago

There is one global JSON.Parameters setup like that, changing few parameters. I want to prevent any future change to global parameters to make a bug somewhere else by not inserting the change to other place in code where parameters are created. So whatever the JSON.Parameters are, I want to be sure to have a copy and change just one (or few) parameters. Instead of:

JSON.Parameters = new JSONParameters
{
  something = true,
  ...,
  somethingElse = false
}
...
JSONParameters other = new JSONParameters
{
  something = true,
  ...,
  somethingElse = false,
  UseExtensions = true
}

I want to have:

JSON.Parameters = new JSONParameters
{
  something = true,
  ...,
  somethingElse = false
}
...
JSONParameters other = JSON.Parameters.MakeCopy();
other.UseExtensions = true;
mgholam commented 5 years ago

Made it public in v2.2.3.1

alesrazym commented 5 years ago

thank you sir