{"id":15035758,"url":"https://github.com/replaysmike/anyserializer","last_synced_at":"2025-04-09T23:15:03.172Z","repository":{"id":33393944,"uuid":"157902540","full_name":"replaysMike/AnySerializer","owner":"replaysMike","description":"A CSharp library that can binary serialize any object quickly and easily","archived":false,"fork":false,"pushed_at":"2023-03-15T03:52:20.000Z","size":312,"stargazers_count":36,"open_issues_count":2,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-09T23:14:57.278Z","etag":null,"topics":["anyserializer","binary","binary-serialization","csharp","csharp-code","deserialization","serialization"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/replaysMike.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-16T17:51:19.000Z","updated_at":"2025-03-05T10:09:13.000Z","dependencies_parsed_at":"2024-10-12T14:20:45.168Z","dependency_job_id":"273c49ba-70ba-40e3-a8b1-67de1084bb74","html_url":"https://github.com/replaysMike/AnySerializer","commit_stats":{"total_commits":97,"total_committers":4,"mean_commits":24.25,"dds":"0.15463917525773196","last_synced_commit":"37ba83f1a91ae9f55bd4808550f1f42f1efa368f"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/replaysMike%2FAnySerializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/replaysMike%2FAnySerializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/replaysMike%2FAnySerializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/replaysMike%2FAnySerializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/replaysMike","download_url":"https://codeload.github.com/replaysMike/AnySerializer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125591,"owners_count":21051770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anyserializer","binary","binary-serialization","csharp","csharp-code","deserialization","serialization"],"created_at":"2024-09-24T20:29:25.018Z","updated_at":"2025-04-09T23:15:03.145Z","avatar_url":"https://github.com/replaysMike.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AnySerializer\n\n[![nuget](https://img.shields.io/nuget/v/AnySerializer.svg)](https://www.nuget.org/packages/AnySerializer/)\n[![nuget](https://img.shields.io/nuget/dt/AnySerializer.svg)](https://www.nuget.org/packages/AnySerializer/)\n[![Build status](https://ci.appveyor.com/api/projects/status/gfwjabg1pta7em94?svg=true)](https://ci.appveyor.com/project/MichaelBrown/anyserializer)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/8001bb10a20c4456a98ed4dde145350a)](https://app.codacy.com/app/replaysMike/AnySerializer?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=replaysMike/AnySerializer\u0026utm_campaign=Badge_Grade_Dashboard)\n[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/85f671af543f46a599cafd10dab36e5a)](https://www.codacy.com/app/replaysMike/AnySerializer?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=replaysMike/AnySerializer\u0026utm_campaign=Badge_Coverage)\n\nA CSharp binary serialization library that can serialize any object quickly and easily. No attributes/decoration required!\n\nThat's right, no need for `[Serializable]` or any other custom attributes on your classes!\n\n## Description\n\nAnySerializer was built for software applications that make manual serialization difficult, or time consuming to decorate and design correctly. Other libraries require custom attributes to define serialization contracts, or fail entirely at more complicated scenarios. That's where AnySerializer shines! It literally is an anything in, anything out binary serializer.\n\n## Installation\nInstall AnySerializer from the Package Manager Console:\n```\nPM\u003e Install-Package AnySerializer\n```\n\n## Usage\n\n```csharp\nusing AnySerializer;\n\nvar originalObject = new SomeComplexTypeWithDeepStructure();\nvar bytes = Serializer.Serialize(originalObject);\nvar restoredObject = Serializer.Deserialize\u003cSomeComplexTypeWithDeepStructure\u003e(bytes);\n\n```\n\n### Ignoring Properties/Fields\n\nIgnoring fields/properties is as easy as using any of the following standard ignores: `[IgnoreDataMember]`, `[NonSerializable]` and `[JsonIgnore]`. Note that `[NonSerializable]` only works on fields, for properties (and/or fields) use `[IgnoreDataMember]`.\n\n### Providing custom type mappings\n\nIf you find you need to map interfaces to concrete types that are contained in different assemblies, you can add custom type mappings:\n\n```csharp\nvar originalObject = new SomeComplexTypeWithDeepStructure();\nvar bytes = Serializer.Serialize(originalObject);\n\nvar typeMaps = TypeRegistry.Configure((config) =\u003e {\n  config.AddMapping\u003cICustomInterfaceName, ConcreteClassName\u003e();\n  config.AddMapping\u003cICustomer, Customer\u003e();\n});\n\nvar restoredObject = Serializer.Deserialize\u003cSomeComplexTypeWithDeepStructure\u003e(bytes, typeMaps);\n```\n\nor alternatively, a type factory for creating empty objects:\n\n```csharp\nvar originalObject = new SomeComplexTypeWithDeepStructure();\nvar bytes = Serializer.Serialize(originalObject);\n\nvar typeMaps = TypeRegistry.Configure((config) =\u003e {\n  config.AddFactory\u003cICustomInterfaceName, ConcreteClassName\u003e(() =\u003e new ConcreteClassName());\n});\n\nvar restoredObject = Serializer.Deserialize\u003cSomeComplexTypeWithDeepStructure\u003e(bytes, typeMaps);\n```\n\nand an alternate form for adding one-or-more mappings:\n\n```csharp\nvar originalObject = new SomeComplexTypeWithDeepStructure();\nvar bytes = Serializer.Serialize(originalObject);\n\nvar typeMap = TypeRegistry.For\u003cICustomInterfaceName\u003e()\n                .Create\u003cConcreteClassName\u003e();\n\nvar restoredObject = Serializer.Deserialize\u003cSomeComplexTypeWithDeepStructure\u003e(bytes, typeMap);\n```\n\nor single type one-or-more factories:\n\n```csharp\nvar originalObject = new SomeComplexTypeWithDeepStructure();\nvar bytes = Serializer.Serialize(originalObject);\n\nvar typeMap = TypeRegistry.For\u003cICustomInterfaceName\u003e()\n                .CreateUsing\u003cConcreteClassName\u003e(() =\u003e new ConcreteClassName());\n\nvar restoredObject = Serializer.Deserialize\u003cSomeComplexTypeWithDeepStructure\u003e(bytes, typeMap);\n```\n\n### Complicated scenarios - Embedded Type Descriptors to the rescue!\n\nThere are some scenarios that cause grief when serializing certain types. Things like abstract interfaces and anonymous types require information about how to serialize them. To solve this, you can choose to embed type information for these scenarios which will increase the size of the serialized data slightly - which is optimized and compressed so it's not that much data.\n\nTo embed type descriptors in the serialized data:\n\n```csharp\nvar originalObject = new SomeComplexTypeWithDeepStructure();\nvar bytes = Serializer.Serialize(originalObject, SerializerOptions.EmbedTypes);\nvar restoredObject = Serializer.Deserialize\u003cSomeComplexTypeWithDeepStructure\u003e(bytes);\n```\n\nWhat does it do? Essentially what is going on here is we store a reference to the assembly and type which tells AnySerializer how to restore the data when deserializing. Only types that are interfaces and anonymous types are stored and concrete classes are ignored. When this _isn't_ applied AnySerializer can still try to figure out what to do, but it doesn't guarantee that it will succeed if types are contained in assemblies it isn't aware of, or where there are multiple concrete classes available for an interface. \n\n### Validating binary data\n\nA validator is provided for verifying if a serialized object contains valid deserializable data that has not been corrupted:\n\n```csharp\nvar originalObject = new SomeComplexTypeWithDeepStructure();\nvar bytes = Serializer.Serialize(originalObject);\nvar isValid = Serializer.Validate(bytes);\nAssert.IsTrue(isValid);\n```\n\n### Extensions\n\nYou can use the extensions to perform serialization/deserialization:\n\n```csharp\nusing AnySerializer.Extensions;\n\nvar originalObject = new SomeComplexTypeWithDeepStructure();\nvar bytes = originalObject.Serialize();\nvar restoredObject = bytes.Deserialize\u003cSomeComplexTypeWithDeepStructure\u003e();\n```\n\n### Capabilities\n\n- [x] All basic types, enums, generics, collections\n- [x] Read-only types\n- [x] Circular references\n- [x] Ignore attributes on unwanted fields/properties\n- [x] Constructorless classes\n- [x] Anonymous types\n- [x] Ignoring of delegates and events, other non-serializable types\n- [x] Resolving abstract interfaces to concrete types\n- [x] Manually specifying custom type mappings through the registry\n- [x] Embedded type descriptors\n- [x] Data validator\n- [x] Custom collections\n- [x] Optional compact mode\n- [x] Compression support\n- [x] Specialized collections (Queue, Stack, ConcurrentDictionary, ConcurrentQueue, ConcurrentStack, ConcurrentBag)\n- [ ] High performance testing and optimization\n\n### Other applications\n\nTo see differences between two serialized objects you can use [AnyDiff](https://github.com/replaysMike/AnyDiff) on your copied object:\n\n```csharp\nusing AnyDiff;\n\nvar object1 = new MyComplexObject(1, \"A string\");\nvar object1bytes = Serializer.Serialize(object1);\nvar object2 = Serializer.Deserialize\u003cMyComplexObject\u003e(object1bytes);\n\nobject2.Id = 100;\n\n// view the changes between them\nvar diff = object1.Diff(object2);\nAssert.AreEqual(diff.Count, 1);\n```\n\nIf you need a way to copy an object that doesn't involve serialization, try [AnyClone](https://github.com/replaysMike/AnyClone) which is a pure reflection based cloning library!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freplaysmike%2Fanyserializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freplaysmike%2Fanyserializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freplaysmike%2Fanyserializer/lists"}