Comments (5)
Thanks for your answer, @etibaldi. Here are some aspects in which Serial differs from Parcelable:
- As mentioned above, Serial is meant for persistent storage, while Parcelable is not, since its binary format is not guaranteed to be stable across versions of Android. Applications end up implementing both Parcelable and other serialization protocols in their model objects.
- Serial has powerful support for debugging, which is critical for persistent storage. Serial detects issues in the input stream as soon as it comes across a field with the wrong type, and throws an exception describing the structure of the object, the mismatched field and the expected field type. In contract, the behavior of Parcelable with invalid input is undefined - it typically crashes the application, but it may just return invalid data.
- Serial adds minimal metadata to the output stream to support backwards compatibility, either through version numbers in all objects or peek of the next field in the stream. Parcelable does not include any extra metadata or support for changes.
- Parcelable requires implementing the Parcelable interface, which is only possible in objects you own. Also, it forces you to couple your model objects with specific serialization schemes, while serializers can be defined separately.
- Last time I checked, Serial is faster than Parcelable in Lollipop and above, since Art precompiles dex files, while Parcelable requires frequent context switching through JNI into the native layer.
@afauci goes into some detail in her post: https://blog.twitter.com/engineering/en_us/topics/open-source/2017/introducing-serial.html.
Ali, what do you think about adding this comparison at the bottom of the readme file?
from serial.
I have the same question, why not use Parcelable to solve your serialized problem?
from serial.
Parcel/Parcelable is not meant to be used for serialization on a persistent storage (check the Parcel javadoc). Try to update the structure of a Parcelable object, then parse the content of old ones.. it will not work, and it will be impossible to debug. They are designed for inter-process communication first.
This library instead seems to handle it, if you check https://github.com/twitter/serial#updating-serializers
I think they just simply chose a similar API to Parcelable, which makes sense because Android developers are used to it.
What will be interesting is a comparison of this library with google protocol buffers.
from serial.
Thank etibaldi, if u want to persist some binary data on storage. Serial is a better choice.
from serial.
from serial.
Related Issues (16)
- Publish it to maven central HOT 2
- Badge for Maven is broken HOT 2
- Source code not distributed with library artifacts HOT 3
- Translate a Chinese README ? HOT 2
- examples? HOT 1
- Stability for production HOT 7
- Can't deserialize - Unknown type 26 HOT 6
- README-CHINESE.rst疑问 HOT 2
- Does Serial Only for android projects HOT 3
- Using Serial for classes where you don't own the super class HOT 1
- changes to continuous integration
- 翻译成kotlin 支持可空的类型 比如Float? Int?
- 对于数组list map 相对于gson 没有有啥 50000的量
- getMapSerializer Example
- I am getting ava.lang.OutOfMemoryError: Java heap space during the Serialization... any clues? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serial.