{"id":16751054,"url":"https://github.com/raftario/serde-partial","last_synced_at":"2026-03-05T00:03:21.724Z","repository":{"id":63944570,"uuid":"571990568","full_name":"raftario/serde-partial","owner":"raftario","description":"Serde partial serialization made easy","archived":false,"fork":false,"pushed_at":"2022-11-30T01:52:27.000Z","size":24,"stargazers_count":42,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-02-27T11:16:14.710Z","etag":null,"topics":["filter","partial","serde","serialization"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/raftario.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-29T10:23:28.000Z","updated_at":"2024-12-30T06:52:47.000Z","dependencies_parsed_at":"2023-01-14T15:45:28.595Z","dependency_job_id":null,"html_url":"https://github.com/raftario/serde-partial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/raftario/serde-partial","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raftario%2Fserde-partial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raftario%2Fserde-partial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raftario%2Fserde-partial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raftario%2Fserde-partial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/raftario","download_url":"https://codeload.github.com/raftario/serde-partial/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/raftario%2Fserde-partial/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30101696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T23:59:36.199Z","status":"ssl_error","status_checked_at":"2026-03-04T23:56:48.556Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["filter","partial","serde","serialization"],"created_at":"2024-10-13T02:42:54.956Z","updated_at":"2026-03-05T00:03:21.681Z","avatar_url":"https://github.com/raftario.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# serde-partial\n\nOne of the few things that still require boilerplate when using Serde is partial serialization.\n\nLet's say we have an API route which returns product information. We want to return the stock only to admins and not to visitors. There are a few options here; have a second struct with a subset of the fields which also derives `Serialize`, make the stock field an `Option` with `#[serde(skip_serializing_if = \"Option::is_none\")]` and set to `None` for visitors, or use something like the `serde_json::json!` macro and do manual serialization.\n\nNone of these options are particularly attractive. Having to maintain a struct and handle conversion for each subset of fields is a lot of boilerplate. Making a field that's always present optional just for serialization is a hack at best. Manual serialization kind of defeats the purpose of serde derives.\n\n`serde-partial` aims to make partial serialization (almost) as clean an concise as complete serialization while also being `no_std` compatible. Using this crate this problem could be solved in a single line.\n\n```rust\nuse serde::Serialize;\nuse serde_partial::SerializePartial;\n\n#[derive(Serialize, SerializePartial)]\npub struct Product {\n    name: String,\n    price: u32,\n    stock: u32,\n}\n\nfn get_product(id: i32) -\u003e Product {\n    todo!()\n}\n\nfn product_api(id: i32, is_manager: bool) -\u003e String {\n    let product = get_product(id);\n    if is_manager {\n        serde_json::to_string(\u0026product).unwrap()\n    } else {\n        serde_json::to_string(\u0026product.without_fields(|p| [p.stock])).unwrap()\n    }\n}\n```\n\nCheck out the [`with_fields`](SerializePartial::with_fields) [documentation](https://docs.rs/serde-partial) for more details and examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraftario%2Fserde-partial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fraftario%2Fserde-partial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fraftario%2Fserde-partial/lists"}