Hello! :-) Guys, why serialization is needed? Any examples? Any gain in application download speed when using it in the next session? If so, by what means?

  • Serialization of whom where? - andreymal
  • 1) maintaining state between requests 2) caching 3) transfer / exchange of data, etc. the question is too general. - teran
  • Roughly speaking, I have an object user with a variety of methods / attributes that change during the session. When the session ends - why should I use serialize, when can I save its current attributes in the database, for example? - OO
  • Or am I doing the same thing as the serialization function? Only in its own way. I mean reinventing the wheel? - OO
  • one
    When you save attributes to the database, they are serialized anyway to the formats used in SQL, so the question is about nothing - andreymal

1 answer 1

Serialization is the process of converting an object (data) into a string. Such a string is usually saved to disk, or sent somewhere over the network for subsequent deserialization and conversion back to an object.

Serialization is usually needed for:

  1. Sending (receiving) an object (data) to another server (service, computer). That is, an object is serialized to a string, then this string is sent somewhere over the network, then from a string is converted back to an object, and there you can work with it as an object.

  2. To save settings or other data to disk for later retrieval and use. For example, make Save the game, save the current state of the program, save the program settings.

I wrote this line as an example, there are different types of serialization, in XML, JSON, binnary (of different types), etc.

Roughly speaking, I have an object user with a variety of methods / attributes that change during the session. When a session ends - why should I use serialize, when can I save its current attributes in the database?

So everything is correct, in the case of information on the user on the site, in most scenarios, the database is saved and serialization is not needed here.

  • and what entry in the database is not serialization? - teran
  • From Wikipedia: Serialization is the process of converting a data structure into a sequence of bits. That is all the same emphasis on the "string" (stream) than on structural storage in the database. - Dmitry Polyanin
  • Well, purely by the name of the methods, save to a database in C# for example, the function on EF is called db.UpdateChanges(); db.UserConfig.Add(userConfig); db.UpdateChanges(); db.UserConfig.Add(userConfig); and serialization is called serializer.Serialize(); . But yes, I agree that from a broader point of view it is possible and how you wrote to call it, it will just be less clear and less common. - Dmitry Polyanin