{"id":4541,"date":"2023-12-23T09:12:43","date_gmt":"2023-12-23T08:12:43","guid":{"rendered":"https:\/\/rock-the-prototype.com\/uncategorized\/serialization-how-does-serialization-of-data-work\/"},"modified":"2023-12-23T11:00:24","modified_gmt":"2023-12-23T10:00:24","slug":"serialization-how-does-serialization-of-data-work","status":"publish","type":"encyclopedia","link":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/","title":{"rendered":"Serialization &#8211; How does serialization of data work?"},"content":{"rendered":"<p><\/p><div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-1 fusion-flex-container nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\"><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:1144px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-0 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:0px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-text fusion-text-1\"><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_86 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Inhaltsverzeichnis<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #ffffff;color:#ffffff\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #ffffff;color:#ffffff\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#What_is_serialization\" >What is serialization?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#Binary_serialization_%E2%80%93_conversion_of_an_object_into_a_sequence_of_binary_bytes\" >Binary serialization &#8211; conversion of an object into a sequence of binary bytes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#How_does_the_serialization_of_data_work\" >How does the serialization of data work?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#What_is_the_purpose_of_serializing_data\" >What is the purpose of serializing data?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#Binary_serialization_and_XML_serialization\" >Binary serialization and XML serialization<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#Why_binary_serialization_opens_up_security_risks\" >Why binary serialization opens up security risks<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#Security_aspects_of_binary_serialization\" >Security aspects of binary serialization<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#Risks_of_binary_serialization\" >Risks of binary serialization<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#Best_practices_for_protection\" >Best practices for protection:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#Tools_and_libraries_for_serialization\" >Tools and libraries for serialization<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#Python\" >Python:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#Java\" >Java:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#JavaScript\" >JavaScript:<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#What_you_should_always_bear_in_mind_when_serializing_XML\" >What you should always bear in mind when serializing XML<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#For_binary_or_XML_serialization_you_need\" >For binary or XML serialization you need:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#Python_%E2%80%93_JSON_serialization\" >Python &#8211; JSON serialization:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#Java_%E2%80%93_Java_object_serialization\" >Java &#8211; Java object serialization<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#JavaScript_%E2%80%93_JSON_serialization\" >JavaScript &#8211; JSON serialization<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"What_is_serialization\"><\/span>What is serialization?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In computer science, <strong>serialization<\/strong> is the <strong>mapping of structured data<\/strong> to a <strong>sequential form of representation<\/strong>.<\/p>\n<p>The <strong>serialization of data<\/strong> is primarily used for <strong>storing objects in files<\/strong> and for <strong>transferring objects via the network<\/strong> in distributed software systems.<\/p>\n\n<\/div><a class=\"fusion-modal-text-link\" data-toggle=\"modal\" data-target=\".fusion-modal.Podcast Software Development - Idea generation and creativity in software development\" href=\"#\"><iframe class=\"lazyload\" style=\"border-radius: 12px;\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20width%3D%27100%27%20height%3D%27352%27%20viewBox%3D%270%200%20100%20352%27%3E%3Crect%20width%3D%27100%27%20height%3D%27352%27%20fill-opacity%3D%220%22%2F%3E%3C%2Fsvg%3E\" data-orig-src=\"https:\/\/open.spotify.com\/embed\/episode\/54PtfzZlt3gTfrxDcx4wrC?utm_source=generator\" width=\"100%\" height=\"352\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/a>\n<div class=\"fusion-text fusion-text-2\"><h2>Binary serialization &ndash; conversion of an object into a sequence of binary bytes<\/h2>\n<p><strong>A<\/strong> special type of <strong>binary serialization<\/strong> is the <strong>conversion of an object into a sequence of bytes<\/strong>.<\/p>\n<p>This enables the <strong>conversion of an object<\/strong> into a <strong>byte stream<\/strong> in order to save the object, transfer it to the working memory, a database or a file.<\/p>\n<div id=\"attachment_3380\" style=\"width: 972px\" class=\"wp-caption alignnone\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3380\" class=\"size-full wp-image-1887\" src=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Serialisierung.jpg\" alt=\"Serialization of data in computer science\" width=\"962\" height=\"828\" srcset=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Serialisierung-200x172.jpg 200w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Serialisierung-300x258.jpg 300w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Serialisierung-400x344.jpg 400w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Serialisierung-600x516.jpg 600w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Serialisierung-768x661.jpg 768w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Serialisierung-800x689.jpg 800w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Serialisierung.jpg 962w\" sizes=\"(max-width: 962px) 100vw, 962px\"><p id=\"caption-attachment-3380\" class=\"wp-caption-text\">Serialization of data in computer science<\/p><\/div>\n<p><strong>Data serialization<\/strong> is therefore a concept and a <strong><br>\n<a href=\"https:\/\/rock-the-prototype.com\/wiki\/design-pattern\/\" target=\"_blank\" rel=\"noopener\">design pattern<\/a><br>\n<\/strong> for <a href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/programming\/\" target=\"_blank\" title=\"What is programming? When programming, a programmer creates a software program that can run on a machine. The code is created in one of the formally defined computer languages - which are countless, such as Java, PHP, C++ or C#, Perl and many many more.\" class=\"encyclopedia\">programming<\/a> languages.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_does_the_serialization_of_data_work\"><\/span>How does the serialization of data work?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>For <strong>serialization<\/strong>, an object is transferred to a <strong>stream of data<\/strong> that contains the data.<\/p>\n<p>The <strong>data stream<\/strong> can also contain information on the<strong> object type<\/strong>, e.g. <strong>version<\/strong>, <strong>data type<\/strong> and <strong>assembly name<\/strong>.<\/p>\n<p>From this <strong>data flow<\/strong>, the object can be saved in a database, a file or a working memory.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_is_the_purpose_of_serializing_data\"><\/span>What is the purpose of serializing data?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The main purpose of <strong>serialization <\/strong>is to save the state of an object so that it can be recreated if necessary.<\/p>\n<p>As a developer, you can therefore save the status of an object at any time and recreate the object as required and perform the following actions:<\/p>\n<ul>\n<li><strong>Sending the object via remote connection<\/strong>, e.g. via web service<\/li>\n<li><strong>Transferring<\/strong><strong>objects<\/strong> from one domain to another<\/li>\n<li>an <strong>object protected<\/strong> via a firewall as <a href=\"https:\/\/rock-the-prototype.com\/wiki\/json\/\"><br>\n<strong>JSON<\/strong><br>\n<\/a>&ndash; or XML string<\/li>\n<li>Manage security and user-specific information about applications<\/li>\n<\/ul>\n<div id=\"attachment_4540\" style=\"width: 1802px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-4540\" class=\"size-full wp-image-4539\" src=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Warum-die-Binaer-Serialisierung-Sicherheitsrisiken-eroeffnet.jpg\" alt=\"Why binary serialization opens up security risks\" width=\"1792\" height=\"1024\" srcset=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Warum-die-Binaer-Serialisierung-Sicherheitsrisiken-eroeffnet-200x114.jpg 200w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Warum-die-Binaer-Serialisierung-Sicherheitsrisiken-eroeffnet-300x171.jpg 300w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Warum-die-Binaer-Serialisierung-Sicherheitsrisiken-eroeffnet-400x229.jpg 400w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Warum-die-Binaer-Serialisierung-Sicherheitsrisiken-eroeffnet-600x343.jpg 600w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Warum-die-Binaer-Serialisierung-Sicherheitsrisiken-eroeffnet-768x439.jpg 768w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Warum-die-Binaer-Serialisierung-Sicherheitsrisiken-eroeffnet-800x457.jpg 800w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Warum-die-Binaer-Serialisierung-Sicherheitsrisiken-eroeffnet-1024x585.jpg 1024w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Warum-die-Binaer-Serialisierung-Sicherheitsrisiken-eroeffnet-1200x686.jpg 1200w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Warum-die-Binaer-Serialisierung-Sicherheitsrisiken-eroeffnet-1536x878.jpg 1536w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Warum-die-Binaer-Serialisierung-Sicherheitsrisiken-eroeffnet.jpg 1792w\" sizes=\"(max-width: 1792px) 100vw, 1792px\"><p id=\"caption-attachment-4540\" class=\"wp-caption-text\">Why binary serialization opens up security risks<\/p><\/div>\n<h2 class=\"heading-anchor\"><span class=\"ez-toc-section\" id=\"Binary_serialization_and_XML_serialization\"><\/span>Binary serialization and XML serialization<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Even if a programming language contains classes for <strong>binary serialization<\/strong> or <strong>XML serialization<\/strong>, these should be used with extreme caution!<\/p>\n<div id=\"attachment_3381\" style=\"width: 444px\" class=\"wp-caption alignnone\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3381\" class=\"size-full wp-image-1888\" src=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Warning.png\" alt=\"Warning\" width=\"434\" height=\"122\" srcset=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Warning-200x56.png 200w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Warning-300x84.png 300w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Warning-400x112.png 400w, https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2022\/07\/Warning.png 434w\" sizes=\"(max-width: 434px) 100vw, 434px\"><p id=\"caption-attachment-3381\" class=\"wp-caption-text\">Warning on the use of serialization in unprotected areas<\/p><\/div>\n<h2 class=\"heading-anchor\"><span class=\"ez-toc-section\" id=\"Why_binary_serialization_opens_up_security_risks\"><\/span>Why binary serialization opens up security risks<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><strong>Binary serialization<\/strong> uses binary coding for the memory or for <strong>socket-based network streams<\/strong> to generate a compact serialization.<\/p>\n<p>With<strong> binary serialization<\/strong>, <strong>all members<\/strong> of the object &ndash; including those with read-only attributes &ndash; are serialized. Serialization therefore always improves the performance of a stream, <strong>BUT<\/strong> the access and rights management implemented in an application is overridden.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Security_aspects_of_binary_serialization\"><\/span>Security aspects of binary serialization<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Binary serialization, in which data structures are converted into a binary format, entails specific security risks that must be carefully considered.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Risks_of_binary_serialization\"><\/span>Risks of binary serialization<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li><strong>Unauthorized code execution<\/strong>: If an attacker can serialize manipulated objects that are then deserialized, this could lead to the execution of malicious code.<\/li>\n<li><strong>Data leaks<\/strong>: Sensitive information could be inadvertently included in the serialized data and then disclosed.<\/li>\n<li><strong>Replay attacks<\/strong>: Without adequate security measures, serialized data could be intercepted and reused to cause unauthorized access or actions.<\/li>\n<li><strong>Injections<\/strong>: Poorly validated input could lead to injection attacks in which unwanted data is fed into the deserialization process.<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Best_practices_for_protection\"><\/span>Best practices for protection:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li><strong>Input <a href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/validation\/\" target=\"_blank\" title=\"Validation is a central activity in data processing. The validation of data is therefore part of the software development process as well as during software operation, i.e. during the actual use of software programs.\" class=\"encyclopedia\">validation<\/a><\/strong>: Ensure that all incoming data is validated before deserialization to detect and prevent malicious data.<\/li>\n<li><strong>Minimize usage<\/strong>: Limit the use of binary serialization to trusted data sources and avoid it where possible.<\/li>\n<li><strong>Use secure libraries<\/strong>: Choose libraries and tools that are known for their security measures and keep them up to date.<\/li>\n<li><strong>Security audits and tests<\/strong>: Conduct regular security audits and penetration tests to identify and fix vulnerabilities.<\/li>\n<li><strong>Object-level access control<\/strong>: Implement access controls that define which objects may and may not be deserialized.<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Tools_and_libraries_for_serialization\"><\/span>Tools and libraries for serialization<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Different programming languages offer different tools and libraries for serialization. Here are some common examples:<\/p>\n<h4><span class=\"ez-toc-section\" id=\"Python\"><\/span>Python:<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li><strong>Pickle<\/strong>: A built-in <a href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/library\/\" target=\"_blank\" title=\"A library refers to a software library as a ready-made collection of code that can be used to perform general software development tasks. Libraries are essentially a collection of functions and procedures that can be called up by other software programs to execute certain functions.\" class=\"encyclopedia\">library<\/a> for the serialization and deserialization of <a href=\"https:\/\/rock-the-prototype.com\/en\/programming-languages-frameworks\/python\/\" target=\"_blank\" title=\"Python is an object-oriented programming language. Python is currently one of the most widely used programming languages. Why you should program in Python...\" class=\"encyclopedia\">Python<\/a> objects. Attention: <code>pickle<\/code> is not secure against erroneous or malicious data and should therefore not be used for data that originates from an unknown source.<\/li>\n<li><strong><a href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/json\/\" target=\"_blank\" title=\"What is JSON? JSON, the JavaScript Object Notation, is a lightweight and flexible data format that is ideal for cross-platform data exchange. It is easy to read, easy to write and is supported by almost all modern programming languages. Thanks to its lean structure, JSON enables efficient data transfer and is indispensable for web applications and APIs.\" class=\"encyclopedia\">JSON<\/a><\/strong>: The <code>json<\/code> library is used for working with JSON data, a text-based and language-independent representation of objects.<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"Java\"><\/span>Java:<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li><strong><a href=\"https:\/\/rock-the-prototype.com\/en\/programming-languages-frameworks\/java\/\" target=\"_blank\" title=\"What is Java suitable for in programming? Java is very popular as the official language for developing Android apps. It is a general purpose programming language. This programming language is supported by Google and a large active community of developers.\" class=\"encyclopedia\">Java<\/a> Serialization API<\/strong>: Enables the serialization of objects into a byte stream, which can then be transferred to files, databases or via networks.<\/li>\n<li><strong>Jackson and Gson<\/strong>: Popular libraries for working with JSON, offering both serialization and deserialization.<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"JavaScript\"><\/span>JavaScript:<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li><strong>JSON.stringify\/JSON.parse<\/strong>: Native methods in JavaScript for serializing and deserializing objects to and from JSON.<\/li>\n<li><strong>BSON<\/strong>: A binary representation of JSON-like documents, often used in conjunction with MongoDB.<\/li>\n<\/ul>\n<p>While serialization is a powerful tool in software development, it poses significant security risks if handled improperly, especially in binary serialization.<\/p>\n<p>A deep understanding of the risks and the implementation of best practices is crucial to mitigate them. At the same time, choosing the right tools and libraries for serialization in your specific programming language is crucial to ensure both the efficiency and security of your applications.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_you_should_always_bear_in_mind_when_serializing_XML\"><\/span>What you should always bear in mind when serializing XML<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In <strong>XML serialization<\/strong>, public data fields, properties of an object, object parameters and return values of methods should be serialized in an XML stream that corresponds to the official <a href=\"https:\/\/www.w3.org\/XML\/Schema\">XML schema definition<\/a>.<\/p>\n<p>XML serialization leads to <strong>strongly typed classes<\/strong> with public properties and fields that are converted to XML.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"For_binary_or_XML_serialization_you_need\"><\/span>For binary or XML serialization you need:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li>the object to be serialized<\/li>\n<li>a stream with the serialized object<\/li>\n<li>a system-specific runtime instance for formatting the object<\/li>\n<\/ol>\n<p>Selectively <strong>mark<\/strong> <strong>attributes<\/strong> in objects <strong>as non-serializable<\/strong> to prevent sensitive data from being serialized.<\/p>\n<p>Even if a field of a <strong>serializable type<\/strong> contains a pointer, a handle or another data structure and is therefore specific to a certain environment, so that this field cannot be meaningfully restored in any other environment, you should mark the type as non-serializable.<\/p>\n<\/div><a class=\"fusion-modal-text-link\" data-toggle=\"modal\" data-target=\".fusion-modal.Podcast Episode 1 - Idea generation and creativity in software development - Rock the Prototype - Software Development\" href=\"#\"><iframe style=\"width: 100%; max-width: 660px; overflow: hidden; border-radius: 10px;\" src=\"https:\/\/embed.podcasts.apple.com\/us\/podcast\/episode-1-idea-generation-and-creativity-in-software\/id1684835330?i=1000611051749\" height=\"175\" frameborder=\"0\" sandbox=\"allow-forms allow-popups allow-same-origin allow-scripts allow-storage-access-by-user-activation allow-top-navigation-by-user-activation\"><\/iframe><\/a>\n<div class=\"fusion-text fusion-text-3\"><p>Here are detailed examples of the implementation of serialization in various programming languages:<\/p>\n<p>&nbsp;<\/p>\n<h3>Python &ndash; JSON serialization:<\/h3>\n<p><code>import json<\/code><\/p>\n<p># A dictionary in Python<br>\n<code> data = <\/code><\/p>\n<p># Serialization: Converting the dictionary into a JSON string<br>\n<code>json_string = json.dumps(data)<\/code><\/p>\n<p># Outputs the JSON string<br>\n<code>print(json_string) <\/code><\/p>\n<p># Deserialization: Converting the JSON string back into a Python dictionary<br>\n<code>parsed_data = json.loads(json_string)<\/code><\/p>\n<p># Outputs the restored dictionary<br>\n<code>print(parsed_data) <\/code><\/p>\n<\/div><div class=\"fusion-text fusion-text-4\"><h3>Java &ndash; Java object serialization<\/h3>\n<p><code>import java.io.*;<\/code><\/p>\n<p><code>public class User implements Serializable <\/code><\/p>\n<\/div><div class=\"fusion-text fusion-text-5\"><h3>JavaScript &ndash; JSON serialization<\/h3>\n<p><code>\/\/ Ein Objekt in JavaScript<br \/>\nlet data = ;<\/code><\/p>\n<p>\/\/ Serialization: Converting the object into a JSON string<br>\n<code>let jsonString = JSON.stringify(data);<\/code><\/p>\n<p><code>console.log(jsonString); \/\/ Gibt den JSON-String aus<\/code><\/p>\n<p>\/\/ Deserialization: Converting the JSON string back into an object<br>\n<code>let parsedData = JSON.parse(jsonString);<\/code><\/p>\n<p>\/\/ Outputs the restored object<br>\n<code>console.log(parsedData); <\/code><\/p>\n<\/div><div class=\"fusion-text fusion-text-6\"><p>These code examples clearly show you how serialization is implemented in Python, Java and JavaScript.<\/p>\n<p>In Python and JavaScript, JSON is usually used for serialization, as it is natively supported and the data can be easily transferred between different systems.<\/p>\n<p>Java provides a built-in facility for serializing objects, which is particularly useful when objects need to be sent over a network or stored in files.<\/p>\n<p>In any case, it is important that you consider the security aspects of serialization, especially if you are working with external data.<\/p>\n<\/div><\/div><\/div><\/div><\/div><div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-2 fusion-flex-container has-pattern-background has-mask-background nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\"><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:1144px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-1 fusion_builder_column_1_1 1_1 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:100%;--awb-margin-top-large:0px;--awb-spacing-right-large:1.92%;--awb-margin-bottom-large:0px;--awb-spacing-left-large:1.92%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><a class=\"fusion-modal-text-link\" data-toggle=\"modal\" data-target=\".fusion-modal.Rock the Prototype - Software development &amp; Prototyping Podcast iTunes\" href=\"#\"><iframe id=\"embedPlayer\" style=\"width: 100%; max-width: 660px; overflow: hidden; border-radius: 10px; transform: translateZ(0px); animation: 2s ease 0s 6 normal none running loading-indicator; background-color: #e4e4e4;\" src=\"https:\/\/embed.podcasts.apple.com\/us\/podcast\/rock-the-prototype-software-development-prototyping\/id1684835330?itsct=podcast_box_player&amp;itscg=30200&amp;ls=1&amp;theme=auto\" height=\"450px\" frameborder=\"0\" sandbox=\"allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation-by-user-activation\"><\/iframe><\/a><\/div><\/div><\/div><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>In computer science, serialization is the mapping of structured data to a sequential form of representation.<\/p>\n","protected":false},"author":1,"featured_media":4538,"template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[1258,1167,1166],"tags":[1912,2162,2112,2113,1144,2158,2120,2159,1464,2154,2152,2155,1142,1951,2153,2160,2166,2165,2167,1147,1146,2161,1173,1262,2164],"class_list":["post-4541","encyclopedia","type-encyclopedia","status-publish","has-post-thumbnail","hentry","category-learn-programming","category-programming-languages-frameworks","category-software-architecture","tag-data","tag-data-stream","tag-data-structure-en","tag-data-structures","tag-design-pattern-en","tag-issued-software-systems","tag-json-en","tag-network","tag-object-orientation","tag-object-oriented-program-models","tag-object-oriented-programming-languages","tag-objects","tag-programming","tag-programming-language","tag-programming-languages","tag-serialize","tag-socket-en","tag-socket-based-network-streams","tag-sockets-en","tag-software-architecture","tag-software-design-en","tag-stream-en","tag-web-app-en","tag-web-apps-en","tag-xml-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Serialization - How does serialization of data work? - How does serializing data work?<\/title>\n<meta name=\"description\" content=\"What is serialization? \u2705 How does serializing data work? \u2705 Why serialize data? Binary serialization &amp; XML serialization \u2705\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Serialization - How does serialization of data work? - How does serializing data work?\" \/>\n<meta property=\"og:description\" content=\"What is serialization? \u2705 How does serializing data work? \u2705 Why serialize data? Binary serialization &amp; XML serialization \u2705\" \/>\n<meta property=\"og:url\" content=\"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/\" \/>\n<meta property=\"og:site_name\" content=\"Rock the Prototype - Softwareentwicklung &amp; Prototyping\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-23T10:00:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Serialisierung.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1792\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/serialization-how-does-serialization-of-data-work\\\/\",\"url\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/serialization-how-does-serialization-of-data-work\\\/\",\"name\":\"Serialization - How does serialization of data work? - How does serializing data work?\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/serialization-how-does-serialization-of-data-work\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/serialization-how-does-serialization-of-data-work\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/rock-the-prototype.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/Serialisierung.jpg\",\"datePublished\":\"2023-12-23T08:12:43+00:00\",\"dateModified\":\"2023-12-23T10:00:24+00:00\",\"description\":\"What is serialization? \u2705 How does serializing data work? \u2705 Why serialize data? Binary serialization & XML serialization \u2705\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/serialization-how-does-serialization-of-data-work\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/serialization-how-does-serialization-of-data-work\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/serialization-how-does-serialization-of-data-work\\\/#primaryimage\",\"url\":\"https:\\\/\\\/rock-the-prototype.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/Serialisierung.jpg\",\"contentUrl\":\"https:\\\/\\\/rock-the-prototype.com\\\/wp-content\\\/uploads\\\/2023\\\/12\\\/Serialisierung.jpg\",\"width\":1792,\"height\":1024,\"caption\":\"Serialisierung\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/learn-programming\\\/serialization-how-does-serialization-of-data-work\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Startseite\",\"item\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/rock-the-prototype\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Prototyping Wiki\",\"item\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/wiki\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Serialization &#8211; How does serialization of data work?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/\",\"name\":\"Rock the Prototype - Softwareentwicklung &amp; Prototyping\",\"description\":\"Prototyping: Software Prototypen, Software entwickeln &amp; Programmieren im Team\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/rock-the-prototype.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Serialization - How does serialization of data work? - How does serializing data work?","description":"What is serialization? \u2705 How does serializing data work? \u2705 Why serialize data? Binary serialization & XML serialization \u2705","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/","og_locale":"en_US","og_type":"article","og_title":"Serialization - How does serialization of data work? - How does serializing data work?","og_description":"What is serialization? \u2705 How does serializing data work? \u2705 Why serialize data? Binary serialization & XML serialization \u2705","og_url":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/","og_site_name":"Rock the Prototype - Softwareentwicklung &amp; Prototyping","article_modified_time":"2023-12-23T10:00:24+00:00","og_image":[{"width":1792,"height":1024,"url":"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Serialisierung.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/","url":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/","name":"Serialization - How does serialization of data work? - How does serializing data work?","isPartOf":{"@id":"https:\/\/rock-the-prototype.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#primaryimage"},"image":{"@id":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#primaryimage"},"thumbnailUrl":"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Serialisierung.jpg","datePublished":"2023-12-23T08:12:43+00:00","dateModified":"2023-12-23T10:00:24+00:00","description":"What is serialization? \u2705 How does serializing data work? \u2705 Why serialize data? Binary serialization & XML serialization \u2705","breadcrumb":{"@id":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#primaryimage","url":"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Serialisierung.jpg","contentUrl":"https:\/\/rock-the-prototype.com\/wp-content\/uploads\/2023\/12\/Serialisierung.jpg","width":1792,"height":1024,"caption":"Serialisierung"},{"@type":"BreadcrumbList","@id":"https:\/\/rock-the-prototype.com\/en\/learn-programming\/serialization-how-does-serialization-of-data-work\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Startseite","item":"https:\/\/rock-the-prototype.com\/en\/rock-the-prototype\/"},{"@type":"ListItem","position":2,"name":"Prototyping Wiki","item":"https:\/\/rock-the-prototype.com\/en\/wiki\/"},{"@type":"ListItem","position":3,"name":"Serialization &#8211; How does serialization of data work?"}]},{"@type":"WebSite","@id":"https:\/\/rock-the-prototype.com\/en\/#website","url":"https:\/\/rock-the-prototype.com\/en\/","name":"Rock the Prototype - Softwareentwicklung &amp; Prototyping","description":"Prototyping: Software Prototypen, Software entwickeln &amp; Programmieren im Team","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/rock-the-prototype.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/encyclopedia\/4541","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/encyclopedia"}],"about":[{"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/types\/encyclopedia"}],"author":[{"embeddable":true,"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/users\/1"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/media\/4538"}],"wp:attachment":[{"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/media?parent=4541"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/categories?post=4541"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rock-the-prototype.com\/en\/wp-json\/wp\/v2\/tags?post=4541"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}