简体   繁体   中英

Java serialization vs JSON

I have to transfer objects in Java through network using UDP datagrams. What format would be better in terms of overhead, no of bytes consumed, speed?. I have tried using Serialization and came to know about JSON. Which one would be better?

Java Serialization - Should be considered only for Java-to-Java communication. An important note is that the class definitions should be on the sending and the receiving ends and often you wouldn't gain much by passing the entire object. I wouldn't rule out RMI as a communication protocol, it does simplify development. However the resulting application components will be hardly coupled which will make it very difficult to replace.

JSON - JSON syntax is basically Javascript and therefore any component with a JS engine will handle its parsing very well - even complicated data-structures will be converted to "living" objects efficiently. JSON parsers exist for practically any language and it is easy to use even when not using a JS engine, (Take google GSon for example that is able to convert JSON into corresponding objets with ease) which makes is a good candidate for cross-language communication.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM