I am wondering what serialized mechanism should we choose when dealing with object transferring over the network. What are the pros and cons ?

I know most of the time we use JSON or XML for AJAX since the transfer format are pretty much Javascript format, and plus JSON is pretty lightweight with its small footprint, therefore is Java serialization totally out of the table ?

推荐答案

一般来说,重要的问题是哪个客户端将接收序列化的对象——浏览器/JavaScript引擎,如(node js)、Java客户端、未知/多个客户端.

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 objects with ease) which makes is a good candidate for cross-language communication - for example in a messaging architecture.

XML- 共享JSON的许多好处-跨语言、轻量级等.例如,Adobe Flex处理XML非常好,甚至比JSON更好.对于json来说,这绝对是一个合适的替身.我个人更喜欢JSON,因为它类似于JS的语法,但是XML也很好.

Java序列化- 应仅考虑用于Java到Java通信.重要的一点是,class definitions应该在发送端和接收端,通常通过传递整个对象不会获得太多好处.我不排除RMI作为通信协议,它确实简化了开发.然而,由此产生的应用程序组件将是硬耦合的,这将使其很难替换.

One more notes - Serialization in general has its overhead. However when the communication is performed over a network the bottleneck is often the network rather than the serialization/deserialization itself.

Json相关问答推荐

将嵌套的json中的字符串强制转换为数字

如何在VegaLite中应用Times New Roman,CaliBiri字体

处理输入数据并转换为更简单的格式-PowerBI

Postgres Select json数组并重新映射属性名称

属性错误:';ActivitiesClient';对象没有属性';base_url';

如何在VB6中将字符串转换或解码为可读格式?

使用 Redis 作为键值存储

在 python 中循环 JSON 数组

删除 JOLT 中的方括号

jq可以在两个JSON对象列表中依次添加对象吗?

JOLT JSON 将值从一对多转换为一对一

使用 jq 和 awk 拆分大型 JSON 文件

如何在 wso2 中组合 2 个 json 有效负载?

如何比较 JSON 文档并返回与 Jackson 或 Gson 的差异?

JSON对象中的JavaScript递归搜索

消息通知产生此内容无法显示

在 Jersey 服务中使用 JSON 对象

如何使用 SwiftyJSON 将字符串转换为 JSON

有没有办法折叠 Postman 中的所有 json 字段

可以在 SharedPreferences 中保存 JSON 数组吗?