• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
fangleSea
博客园    首页    新随笔    联系   管理    订阅  订阅
网络知识|序列化和非序列化以及选择

1.JSON

  • one of simplest and most popular formats
  • We can represent an object in plain text with fields of type: String, Number, Boolean, Array, Object

Example:

Adv:

  • Simple and human readable
    • Even after serialization we can understand it and debug it
    • It's plain text so we can create the object and send it without any special software
  • Programming language independent
  • Easy integration with JavaScript/Front-End
    • JavaScript Object Notation is very similar to JavaScript Object representation

Deserialization:

2. Java Object Seralization

  • The class needs to match the original class definition
  • The class has to have an accessible no-args constructor
  • If either of the conditions are violated, we will get an InvalidClassException during the deseralization process

Advantages:

  • Guarantees about correst state reconstruction without any type ambiguity
  • Very clear source of truth for the object we want to send over the network
  • Native support in all the JVM languages
    • No need for external libraries
    • Simple development process

Disadvantages:

  • Not human readable, harder to test
    • We need to import the class and write a Java program to send a message to the server
  • Tight coupling to JVM languages
    • Won't work if we want to exchange messages with applications written in Golong/G++ for example
    • That is a big problem for building a distributed system that utilizes different technologies and runs on different platforms.

3. Google's Protocol Buffers

Advantages

  • No type ambiguity
  • Clear and well defined schema
  • Language independent thanks to the 2 step process
    • Proto file definition
    • Language specific stub generation using proto compiler
  • Efficient serialization & deserialization
  • Security

Disadvantages

  • Not Human readable
  • Hard to debug
  • More complex development process
    • Proto file definition
    • Stub generation

 

posted on 2024-01-04 04:23  跪求个offer  阅读(47)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3