{"id":34837067,"url":"https://github.com/modelingevolution/json-parsable-converter","last_synced_at":"2026-01-20T17:54:01.728Z","repository":{"id":303247006,"uuid":"1014857189","full_name":"modelingevolution/json-parsable-converter","owner":"modelingevolution","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-01T19:39:42.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-03T05:22:55.875Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/modelingevolution.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,"zenodo":null}},"created_at":"2025-07-06T14:47:23.000Z","updated_at":"2025-09-01T19:39:27.000Z","dependencies_parsed_at":"2025-07-06T15:54:23.859Z","dependency_job_id":null,"html_url":"https://github.com/modelingevolution/json-parsable-converter","commit_stats":null,"previous_names":["modelingevolution/json-parsable-converter"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/modelingevolution/json-parsable-converter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modelingevolution%2Fjson-parsable-converter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modelingevolution%2Fjson-parsable-converter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modelingevolution%2Fjson-parsable-converter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modelingevolution%2Fjson-parsable-converter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/modelingevolution","download_url":"https://codeload.github.com/modelingevolution/json-parsable-converter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/modelingevolution%2Fjson-parsable-converter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28032374,"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","status":"online","status_checked_at":"2025-12-25T02:00:05.988Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-12-25T16:07:00.259Z","updated_at":"2025-12-25T16:08:42.875Z","avatar_url":"https://github.com/modelingevolution.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JsonParsableConverter\n\n[![NuGet](https://img.shields.io/nuget/v/ModelingEvolution.JsonParsableConverter.svg)](https://www.nuget.org/packages/ModelingEvolution.JsonParsableConverter/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![.NET](https://img.shields.io/badge/.NET-9.0-blue.svg)](https://dotnet.microsoft.com/download)\n\nA high-performance System.Text.Json converter for types implementing `IParsable\u003cT\u003e`. This library enables seamless JSON serialization/deserialization for custom value types, records, and structs using the standard .NET `IParsable` pattern.\n\n## Features\n\n- 🚀 **High Performance**: Leverages System.Text.Json for optimal performance\n- 🎯 **Type Safe**: Full compile-time type safety with generic constraints\n- 🔧 **Easy Integration**: Simple registration with JsonSerializerOptions\n- 📦 **Minimal Dependencies**: Only depends on System.Text.Json\n- 🧩 **DDD Friendly**: Perfect for Domain-Driven Design value objects and strongly-typed IDs\n\n## Installation\n\n```bash\ndotnet add package ModelingEvolution.JsonParsableConverter\n```\n\n## Quick Start\n\n### Define a Parsable Type\n\n```csharp\nusing System.Text.Json.Serialization;\nusing ModelingEvolution.JsonParsableConverter;\n\n[JsonConverter(typeof(JsonParsableConverter\u003cProductId\u003e))]\npublic readonly record struct ProductId(Guid Value) : IParsable\u003cProductId\u003e\n{\n    public static ProductId Parse(string s, IFormatProvider? provider) \n        =\u003e new(Guid.Parse(s));\n    \n    public static bool TryParse(string? s, IFormatProvider? provider, out ProductId result)\n    {\n        if (Guid.TryParse(s, out var guid))\n        {\n            result = new ProductId(guid);\n            return true;\n        }\n        result = default;\n        return false;\n    }\n    \n    public override string ToString() =\u003e Value.ToString();\n}\n```\n\n### Usage\n\nWith the attribute applied, the type automatically uses the converter - no additional configuration needed:\n\n```csharp\nvar productId = new ProductId(Guid.NewGuid());\n\n// Just works - no special JsonSerializerOptions needed!\nstring json = JsonSerializer.Serialize(productId);\nProductId deserialized = JsonSerializer.Deserialize\u003cProductId\u003e(json);\n```\n\n## Advanced Usage\n\n### More Examples\n\nString-based value type:\n```csharp\n[JsonConverter(typeof(JsonParsableConverter\u003cCustomerName\u003e))]\npublic readonly record struct CustomerName(string Value) : IParsable\u003cCustomerName\u003e\n{\n    public static CustomerName Parse(string s, IFormatProvider? provider) \n        =\u003e new(s);\n    \n    public static bool TryParse(string? s, IFormatProvider? provider, out CustomerName result)\n    {\n        result = new CustomerName(s ?? string.Empty);\n        return s != null;\n    }\n    \n    public override string ToString() =\u003e Value;\n}\n```\n\nComplex value type with validation:\n```csharp\n[JsonConverter(typeof(JsonParsableConverter\u003cEmail\u003e))]\npublic readonly record struct Email : IParsable\u003cEmail\u003e\n{\n    private readonly string _value;\n    \n    public Email(string value)\n    {\n        if (!IsValid(value))\n            throw new ArgumentException(\"Invalid email format\", nameof(value));\n        _value = value;\n    }\n    \n    public static Email Parse(string s, IFormatProvider? provider)\n    {\n        if (!IsValid(s))\n            throw new FormatException($\"Invalid email format: {s}\");\n        return new Email(s);\n    }\n    \n    public static bool TryParse(string? s, IFormatProvider? provider, out Email result)\n    {\n        if (s != null \u0026\u0026 IsValid(s))\n        {\n            result = new Email(s);\n            return true;\n        }\n        result = default;\n        return false;\n    }\n    \n    private static bool IsValid(string email) \n        =\u003e !string.IsNullOrWhiteSpace(email) \u0026\u0026 email.Contains('@');\n    \n    public override string ToString() =\u003e _value;\n}\n```\n\n### Using in Complex Types\n\nSince the converter is applied via attributes, it works seamlessly in complex objects:\n\n```csharp\npublic class Order\n{\n    public OrderId Id { get; set; }\n    public CustomerId CustomerId { get; set; }\n    public Money TotalAmount { get; set; }\n    public DateOnly OrderDate { get; set; }\n}\n\npublic class Customer\n{\n    public CustomerId Id { get; set; }\n    public CustomerName Name { get; set; }\n    public Email Email { get; set; }\n}\n\n// No special configuration needed - just serialize!\nvar customer = new Customer \n{ \n    Id = CustomerId.Parse(\"12345\", null),\n    Name = new CustomerName(\"John Doe\"),\n    Email = Email.Parse(\"john@example.com\", null)\n};\n\nstring json = JsonSerializer.Serialize(customer);\nCustomer deserialized = JsonSerializer.Deserialize\u003cCustomer\u003e(json);\n```\n\n## Why IParsable?\n\nThe `IParsable\u003cT\u003e` interface was introduced in .NET 7 as a standard way to define parsing behavior for custom types. Using this pattern with JSON serialization provides:\n\n1. **Consistency**: Same parsing logic for JSON, string manipulation, and user input\n2. **Maintainability**: Single source of truth for parsing logic\n3. **Framework Support**: Leverages built-in .NET abstractions\n4. **Type Safety**: Compile-time guarantees with generic constraints\n\n## Performance\n\nThis converter is designed for high performance:\n- Zero allocations for value type conversions\n- Minimal overhead compared to manual serialization\n- Efficient string handling using `Utf8JsonReader/Writer`\n\n## Requirements\n\n- .NET 9.0 or higher\n- System.Text.Json\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgments\n\nThis converter is inspired by the need for better value object support in System.Text.Json and is based on patterns from the [MicroPlumberd](https://github.com/modelingevolution/micro-plumberd) project.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodelingevolution%2Fjson-parsable-converter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodelingevolution%2Fjson-parsable-converter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodelingevolution%2Fjson-parsable-converter/lists"}