Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the serializations provided by Java by default

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what is the serialization provided by Java by default". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Serialization (encoding) serializes objects into binary form (byte array), which is mainly used for network transmission, data persistence, etc., while deserialization (decoding) restores the byte array read from network, disk, etc., to the original object, which is mainly used for decoding network transmission objects in order to complete remote calls.

The key factors that affect the serialization performance: serialized code stream size (network bandwidth consumption), serialized performance (CPU resource consumption), whether to support cross-language (heterogeneous system docking and development language switching).

Serialization provided by Java by default: cannot cross languages, serialized code stream is too large, serialized performance is poor

XML, advantages: good man-machine readability, can specify the name of the element or feature. Disadvantages: serialized data contains only the data itself and the structure of the class, excluding type identification and assembly information; can only serialize common properties and fields; cannot serialize methods; the file is large, the file format is complex, and transmission takes up bandwidth. Applicable scenario: as a configuration file to store data, real-time data conversion.

JSON is a lightweight data exchange format, which has the advantages of high compatibility, simple data format, easy to read and write, small serialized data, good scalability and good compatibility. Compared with XML, its protocol is relatively simple and the parsing speed is faster. Disadvantages: the description of the data is worse than XML, it is not suitable for the situation where the performance requirement is ms level, and the extra space overhead is relatively large. Applicable scenarios (alternative to XML): services with cross-firewall access, high scalability, Web browser-based Ajax requests, relatively small amount of data transmission, and relatively low real-time requirements (such as seconds).

Fastjson, which adopts an algorithm of "assuming ordered fast matching". Advantages: the interface is easy to use and the fastest json library in the java language at present. Disadvantages: too much emphasis on speed, deviating from the "standard" and functionality, poor code quality, and incomplete documentation. Applicable scenarios: protocol interaction, Web output, Android client

Thrift is not only a serialization protocol, but also a RPC framework. Advantages: serialized small size, high speed, support for multiple languages and rich data types, strong compatibility for the addition and deletion of data fields, support for binary compression coding. Disadvantages: fewer users, insecure and unreadable when accessing across firewalls, relatively difficult to debug code, cannot be used with other transport layer protocols (such as HTTP), and cannot support reading and writing data directly to the persistence layer, that is, it is not suitable to be a data persistence serialization protocol. Applicable scenario: RPC solution for distributed system

A subproject of Avro,Hadoop that solves the verbosity of JSON and the absence of IDL. Advantages: support rich data types, simple dynamic language combination function, with self-description attributes, improve the speed of data analysis, fast and compressible binary data form, can achieve remote procedure call RPC, support cross-programming language implementation. Disadvantages: it is not intuitive for users accustomed to statically typed languages. Applicable scenarios: make persistent data formats of Hive, Pig and MapReduce in Hadoop.

Protobuf, which describes the data structure as a .proto file, and the code generation tool can generate POJO objects and Protobuf-related methods and properties of the corresponding data structure. Advantages: small code stream after serialization, high performance, structured data storage format (XML JSON, etc.), by identifying the order of fields, you can achieve forward compatibility of the protocol, structured documents are easier to manage and maintain. Disadvantages: need to rely on tools to generate code, support relatively few languages, official support only Java, C++, python. Applicable scenarios: RPC calls with high performance requirements, good access properties across firewalls, and persistence of application layer objects

Other

Protostuff is based on protobuf protocol, but does not need to configure proto file, Jboss marshaling can serialize java class directly without real java.io.Serializable interface Message pack an efficient binary serialization format Hessian binary protocol lightweight remoting onhttp tool kryo based on protobuf protocol, only support java language, need to register (Registration), then serialize (Output), deserialize (Input)

This is the end of the content of "what serialization is provided by Java by default". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report