{"id":18376303,"url":"https://github.com/kubagdynia/dapper.customtypehandlers","last_synced_at":"2026-04-13T23:32:38.238Z","repository":{"id":91383490,"uuid":"234747578","full_name":"kubagdynia/Dapper.CustomTypeHandlers","owner":"kubagdynia","description":"Dapper custom type handlers to serialize/deserialize objects to Xml and Json. Can be also used to map GUID to a string.","archived":false,"fork":false,"pushed_at":"2025-02-13T19:50:46.000Z","size":107,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T04:42:54.628Z","etag":null,"topics":["dapper","database","dotnet-core","json-deserialization","json-mapper","json-serialization","orm","xml-deserialization","xml-mapping","xml-serialization"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kubagdynia.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":"2020-01-18T14:33:31.000Z","updated_at":"2025-02-13T19:47:38.000Z","dependencies_parsed_at":"2023-11-18T21:26:50.917Z","dependency_job_id":"36bf497a-e4ae-4963-a81d-86930bb34668","html_url":"https://github.com/kubagdynia/Dapper.CustomTypeHandlers","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubagdynia%2FDapper.CustomTypeHandlers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubagdynia%2FDapper.CustomTypeHandlers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubagdynia%2FDapper.CustomTypeHandlers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kubagdynia%2FDapper.CustomTypeHandlers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kubagdynia","download_url":"https://codeload.github.com/kubagdynia/Dapper.CustomTypeHandlers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345281,"owners_count":21088242,"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":["dapper","database","dotnet-core","json-deserialization","json-mapper","json-serialization","orm","xml-deserialization","xml-mapping","xml-serialization"],"created_at":"2024-11-06T00:22:47.155Z","updated_at":"2026-04-13T23:32:38.172Z","avatar_url":"https://github.com/kubagdynia.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dapper.CustomTypeHandlers [![NuGet Version](https://img.shields.io/nuget/v/Dapper.CustomTypeHandlers.svg?style=flat)](https://www.nuget.org/packages/Dapper.CustomTypeHandlers/) \n\nDapper custom type handlers to serialize/deserialize objects to Xml and Json. Can be also used to map GUID to a string.\n\n### Installation\nUse NuGet Package Manager\n```\nInstall-Package Dapper.CustomTypeHandlers\n```\nor .NET CLI\n```\ndotnet add package Dapper.CustomTypeHandlers\n```\n\nor just copy into the project file to reference the package\n```\n\u003cPackageReference Include=\"Dapper.CustomTypeHandlers\" Version=\"2.3.0\" /\u003e\n```\n\n### How to use\n- Create class that implements **IXmlObjectType** or **IJsonObjectType** interface\n```csharp\npublic class Book\n{\n\tpublic long Id { get; set; }\n\tpublic string Title { get; set; }\n\tpublic BookDescription Description { get; set; }\n}\n\npublic class BookDescription : IXmlObjectType\n{\n\tpublic Learn Learn { get; set; }\n\tpublic string About { get; set; }\n\tpublic Features Features { get; set; }\n}\n\npublic class Learn\n{\n\tpublic List\u003cstring\u003e Points { get; set; }\n}\n\npublic class Features\n{\n\tpublic List\u003cstring\u003e Points { get; set; }\n}\n```\n- Register these new classes in **Startup.cs**\n```csharp\nservices.RegisterDapperCustomTypeHandlers(typeof(Book).Assembly);\n```\n- Create table in a database that contains a column of the XML type (SQL Server)\n```sql\nCREATE TABLE [dbo].[Books](\n\t[Id] bigint IDENTITY(1,1) NOT NULL,\n\t[Title] nvarchar(200) NOT NULL,\n\t[Description] xml NULL\n\tCONSTRAINT [PK_Books] PRIMARY KEY CLUSTERED\n\t(\n\t\t[Id] ASC\n\t)\n)\n```\nTo persist object as a JSON,  you can use the nvarchar field (class should implement IJsonObjectType)\n```sql\nCREATE TABLE [dbo].[Books](\n\t[Id] bigint IDENTITY(1,1) NOT NULL,\n\t[Title] nvarchar(200) NOT NULL,\n\t[Description] nvarchar(max) NULL\n\tCONSTRAINT [PK_Books] PRIMARY KEY CLUSTERED\n\t(\n\t\t[Id] ASC\n\t)\n)\n```\n\n- Use Dapper to save object data in the database\n```csharp\npublic async Task SaveBook(Book book)\n{\n\tusing (var conn = _connectionFactory.Connection())\n\t{\n\t\tawait conn.ExecuteAsync(_@\"INSERT INTO Books (Title, Description) VALUES (@Title, @Description)\", book);\n\t}\n}\n```\n\n### How to Test\nEvery commit or pull request is built and tested on the Continuous Integration system.\n\nTo test locally:\n- Download and install [.NET 8.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/8.0)\n- Clone or download source code\n```\ngit clone https://github.com/kubagdynia/Dapper.CustomTypeHandlers.git\n```\n- Start tests from the command line\n```\ndotnet test ./Dapper.CustomTypeHandlers/\n```\n\n### Code Examples\n\n- DapperMappers - An example of using Dapper with the custom Xml and Json mappers\n  https://github.com/kubagdynia/DapperMappers\n\n\n### Technologies\nList of technologies, frameworks and libraries used for implementation:\n- [.NET 8.0](https://dotnet.microsoft.com/en-us/download/dotnet/8.0) (platform)\n- [Dapper](https://github.com/StackExchange/Dapper) (micro ORM)\n- [System.Text.Json](https://www.nuget.org/packages/System.Text.Json) (JSON serialization/deserialization)\n- [NUnit](https://nunit.org/) (testing framework)\n- [SQLite](https://www.sqlite.org/) (database for testing purpose)\n- [FluentAssertions](https://github.com/fluentassertions/fluentassertions) (fluent API for asserting the result of unit tests)\n\n### License\nThis project is licensed under the [MIT License](https://opensource.org/licenses/MIT).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubagdynia%2Fdapper.customtypehandlers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkubagdynia%2Fdapper.customtypehandlers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkubagdynia%2Fdapper.customtypehandlers/lists"}