{"id":30719829,"url":"https://github.com/dankinsoid/codableproxies","last_synced_at":"2025-09-03T10:42:20.468Z","repository":{"id":196270719,"uuid":"695646596","full_name":"dankinsoid/CodableProxies","owner":"dankinsoid","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-01T07:31:33.000Z","size":148,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-29T20:46:02.142Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/dankinsoid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"dankinsoid","open_collective":"voidilov-daniil","ko_fi":"dankinsoid","custom":["https://paypal.me/voidilovuae"]}},"created_at":"2023-09-23T19:46:28.000Z","updated_at":"2024-07-31T05:40:57.000Z","dependencies_parsed_at":"2023-09-29T11:35:38.112Z","dependency_job_id":null,"html_url":"https://github.com/dankinsoid/CodableProxies","commit_stats":null,"previous_names":["dankinsoid/codableproxies"],"tags_count":8,"template":false,"template_full_name":"dankinsoid/iOSLibraryTemplate","purl":"pkg:github/dankinsoid/CodableProxies","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FCodableProxies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FCodableProxies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FCodableProxies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FCodableProxies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dankinsoid","download_url":"https://codeload.github.com/dankinsoid/CodableProxies/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dankinsoid%2FCodableProxies/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273431361,"owners_count":25104491,"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-09-03T02:00:09.631Z","response_time":76,"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-09-03T10:42:19.587Z","updated_at":"2025-09-03T10:42:20.450Z","avatar_url":"https://github.com/dankinsoid.png","language":"Swift","funding_links":["https://github.com/sponsors/dankinsoid","https://opencollective.com/voidilov-daniil","https://ko-fi.com/dankinsoid","https://paypal.me/voidilovuae"],"categories":[],"sub_categories":[],"readme":"# CodableProxies\n\n`CodableProxies` provides powerful encoding and decoding strategies for Swift's `Codable` types. By wrapping your encoders and decoders in `DecoderProxy` and `EncoderProxy`, you can easily apply these strategies for a more flexible and versatile encoding/decoding experience.\n\n## Features\n\n- 🚀 Flexible Encoding/Decoding strategies.\n- 🔄 Symmetric Encoding and Decoding support through union types.\n- 🐍 Convert from/to SnakeCase, CamelCase keys.\n- 🔢 Custom strategies for numbers, dates, URLs, etc.\n- 📦 Easily extensible.\n\n## Usage\n\n### Example\n\n```swift\nstruct User: Codable {\n    let isActive: Bool\n    let birthDate: Date\n    ...\n}\n\nlet userJSON = \"\"\"\n{\n    \"isActive\": \"yes\",\n    \"birthDate\": \"1990-01-01T00:00:00Z\",\n    ...\n}\n\"\"\"\n\nlet decoder = DecoderProxy(JSONDecoder(), strategy: [.default, .Bool.string, .Date.iso8601])\nlet user = try decoder.decode(User.self, from: userJSON.data(using: .utf8)!)\n```\n\n### Initialization\n\nWrap your encoders and decoders:\n\n```swift\nlet encoder = EncoderProxy(JSONEncoder(), strategy: [.Bool.string, .Date.iso8601])\nlet decoder = DecoderProxy(JSONDecoder(), strategy: [.Bool.string, .Date.iso8601])\n```\n\n### Available strategies\n#### [Full list](/Strategies.md)\n\n- **`.Bool`**: `decodeFromString`, `string`.\n- **`.Data`**: `base64`.\n- **`.Date`**: `date`, `iso8601`, `formatted(formatter:)`, `timestamp`.\n- **`.Decimal`**: `string`, `number`.\n- **`.Keys`**: `useDefaultKeys`, `snakeCase`, `camelCase`, `custom(...)`.\n- **`.Numeric`**: `string`.\n- **`.Optional`**: `encodeNull`.\n- **`.URL`**: `uri`.\n\n\n### Union Types\n\nThe library offers `CodingProxy` and `CodingStrategy` that bring together both encoding and decoding for symmetrical operations.\n\n## 📝 Combining Encoding and Decoding Strategies\n\nWhen setting multiple strategies, the behavior varies between encoding and decoding:\n\n### Encoding:\nIf you combine multiple encoding strategies for the same type, only the **last strategy specified** will be applied. Strategies specified earlier will be overridden.\n\n**Example:**\nUsing ` [.Date.iso8601, .Date.timestamp]` for encoding will result in the date being encoded as a timestamp, as `.Date.timestamp` is the last strategy listed.\n\n### Decoding:\nFor decoding, if multiple strategies are specified for the same type, all of them will be attempted in the order they are provided. Decoding will succeed if any of the strategies succeeds. If all custom strategies fail, the original strategy of the decoder will be used as a fallback.\n\n**Example:**\nWith ` [.Date.iso8601, .Date.timestamp]` for decoding, the proxy will first attempt to decode the date in the ISO8601 format. If that fails, it will then try to decode it as a timestamp. If both strategies fail, the date will be decoded using the decoder's original strategy.\n\n## ⚠️ Important Note on Custom Type Encoding/Decoding\n\nWhen utilizing `CodableProxies`, it's crucial to understand that the library will **override and ignore** any custom encoding and decoding strategies set on the original encoders/decoders. This behavior particularly impacts the following types when used with `JSONEncoder`, `JSONDecoder`, `PropertyListEncoder`, and `PropertyListDecoder`:\n- `Decimal`\n- `URL`\n- `Data`\n- `Date`\n\nTo maintain consistency and avoid unexpected outcomes, always include strategies for these types in your proxy encoder/decoder. Conveniently, all these strategies are bundled within `EncoderStrategy.default` and `DecoderStrategy.default`.\n\n## Upcoming Enhancements:\n\n- **Diagnostic Tools**: Introduce strategies and utilities to aid in testing encoders and decoders, such as `EncodingStrategy.print`.\n- **Collection Handling**: Implement strategies like `.Collection.nilIfEmpty` and `.Collection.emptyIfNil` to better manage collection states.\n- **Structural Strategies**: Develop strategies that work with deep keys, allowing for nuanced modifications in object structures.\n- **Enhanced Flexibility**: Further refine and expand the range of available strategies for broader use cases and adaptability.\n\n## Installation\n\n1. [Swift Package Manager](https://github.com/apple/swift-package-manager)\n\nCreate a `Package.swift` file.\n```swift\n// swift-tools-version:5.7\nimport PackageDescription\n\nlet package = Package(\n  name: \"SomeProject\",\n  dependencies: [\n    .package(url: \"https://github.com/dankinsoid/CodableProxies.git\", from: \"1.1.3\")\n  ],\n  targets: [\n    .target(name: \"SomeProject\", dependencies: [\"CodableProxies\"])\n  ]\n)\n```\n```ruby\n$ swift build\n```\n\n## Author\n\ndankinsoid, voidilov@gmail.com\n\n## License\n\nCodableProxies is available under the MIT license. See the LICENSE file for more info.\n\n## Contribution\n\nContributions are always welcome! Please refer to our contribution guidelines.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdankinsoid%2Fcodableproxies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdankinsoid%2Fcodableproxies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdankinsoid%2Fcodableproxies/lists"}