{"id":18554781,"url":"https://github.com/microg/safeparcel","last_synced_at":"2025-04-09T23:31:48.781Z","repository":{"id":25414661,"uuid":"28843808","full_name":"microg/SafeParcel","owner":"microg","description":"Helper library and format description for SafeParcel, a version-agnostic parcelable serializer","archived":false,"fork":false,"pushed_at":"2023-04-15T22:04:35.000Z","size":199,"stargazers_count":32,"open_issues_count":2,"forks_count":14,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-24T13:43:54.157Z","etag":null,"topics":["android","android-library","java","microg","parcelables","serialization"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSES/Apache-2.0.txt","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},"funding":{"github":["mar-v-in"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":"microG","issuehunt":null,"otechie":null,"custom":null}},"created_at":"2015-01-06T02:54:49.000Z","updated_at":"2025-01-10T00:05:34.000Z","dependencies_parsed_at":"2024-11-06T21:27:49.111Z","dependency_job_id":null,"html_url":"https://github.com/microg/SafeParcel","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microg%2FSafeParcel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microg%2FSafeParcel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microg%2FSafeParcel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microg%2FSafeParcel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microg","download_url":"https://codeload.github.com/microg/SafeParcel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248129862,"owners_count":21052652,"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":["android","android-library","java","microg","parcelables","serialization"],"created_at":"2024-11-06T21:23:51.602Z","updated_at":"2025-04-09T23:31:46.330Z","avatar_url":"https://github.com/microg.png","language":"Java","funding_links":["https://github.com/sponsors/mar-v-in","https://liberapay.com/microG"],"categories":[],"sub_categories":[],"readme":"\u003c!--\nSPDX-FileCopyrightText: 2016, microg Project Team\nSPDX-License-Identifier: CC-BY-SA-4.0\n--\u003e\n\nSafeParcel\n==========\n\nSafeParcel is a mechanism to serialize objects on the Android platform into Parcelables version-agnostic.\n\nThis is achieved by prefixing each field with a unique identifying number and its length.\nWhen deserializing, unknown fields can be skipped and the field order is not relevant.\n\nThe SafeParcel format was originally developed by Google for Play Services.\nUntil now, neither the format description, nor a library to use it had been released by Google.\n\nFor this reason, although we spent much effort into it, we can't guarantee that this implementation is 100% compatible\nwith Google's implementation.\n\nUsage\n-----\n\nSafeParcel is in the Maven Central Repository. To use it, just add the following dependency statement to your\nAndroid app or library:\n\n    compile 'org.microg:safe-parcel:[version]'\n\nTo find the latest available version, [check the central repository](https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.microg%22%20AND%20a%3A%22safe-parcel%22)\n\n### Directly accessing SafeParcel format\n\nThe `SafeParcelReader` and `SafeParcelWriter` allow to directly read from or write to the SafeParcel format.\nHowever, usage of them requires some amount of code to be written,\nwhich is painful if you want to store many objects in SafeParcel format.\nTherefor, there is a more automatic approach based on reflection build into the library\n\n### Automatic safe parceling\n\nThe `SafeParcelUtil` provides several easy methods to use the SafeParcel format to serialize and deserialize object.\nThe three methods `createObject`, `readObject` and `writeObject` allow to create an object from parcel,\nread from parcel into an existing object or write an object into a parcel.\n\nTo use these, you first need to annotate the fields in the object you want to parcel and make the object implement the SafeParcelable interface.\nIn most cases you simply add the `@SafeParceled` annotation to give each field a unique number.\nWhen using ArrayLists, it is required to further annotate the field. Check documentation of `@SafeParceled` for details.\nAdditionally, make sure that the object has a default or no-parameter constructor.\nIf you don't want such a constructor to be part of the API, make the constructor private.\n\nFor convenience, you can even skip the work of calling the methods in `SafeParcelUtil` by extending the abstract\n`AutoSafeParcelable` class. After that, the only thing required to unparcel the object is to add a static `CREATOR` field with an `AutoCreator` value, check the example below.\n\n### Example\n\n```java\nimport org.microg.safeparcel.*;\n\npublic class ExampleObject extends AutoSafeParcelable {\n    @SafeParceled(1000)\n    private int versionCode = 1;\n\n    @SafeParceled(1)\n    public String name;\n\n    @SafeParceled(value=2, subClass=Integer.class)\n    public List\u003cInteger\u003e ids = new ArrayList\u003cInteger\u003e();\n\n    public static final Creator\u003cExampleObject\u003e CREATOR = new AutoCreator\u003cExampleObject\u003e(ExampleObject.class);\n}\n```\n\nNote: When using ProGuard and automatic safe parceling, make sure that all relevant classes and\nannotations are available at runtime, as SafeParcelUtil will use reflection. See `proguard.txt` for relevant proguard rules.\n\nSafeParcel design patterns\n--------------------------\n\nIt is recommended to add a version code to the fields being parceled in a SafeParcel object.\nAlthough the SafeParcel format is version-agnostic, your code may be not.  With a version code,\nyou can realize that the object was deserialized from an older version and ensure that fields that did not\nexist previously are populated.\n\nAdditionally it turned out to be a good idea to not remove fields that have been used in the previous version of your\napp or library. This way, code relying on the old version will continue to work. For performance reason or if it is an\nunreasonable amount of work to manage the old code, you can still remove the field in a future version, after having\nthe field being marked as deprecated for some time.\n\nLicense\n-------\n- Code is licensed under [Apache License 2.0](LICENSES/Apache-2.0)\n- Documentation and artwork are licensed under [Creative Commons Attribution-ShareAlike 4.0](LICENSES/CC-BY-SA-4.0)\n- Some files are placed unter the public domain using [Creative Commons CC0 1.0 Public Domain Dedication](LICENSES/CCO-1.0)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrog%2Fsafeparcel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrog%2Fsafeparcel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrog%2Fsafeparcel/lists"}