Java序列化对象与非序列化对象 [英] Java Serialised object vs Non serialised object

查看:688
本文介绍了Java序列化对象与非序列化对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)非序列化的java对象是否可以通过网络发送,由另一个JVM执行或存储在本地文件存储中以恢复数据?
2)序列化和存储java对象与存储java对象而不序列化之间的区别是什么?

1) Can a non-serialised java object be sent over the network to be executed by another JVM or stored in local file storage to get the data restored? 2) What is the difference between serialising and storing the java object vs storing the java object without serialising it?

推荐答案

序列化是一种将java对象表示为一系列字节的方法。它只是一种格式。
内置java序列化是一个类,它提供用于将java对象转换为一系列字节的API。而已。当然,反序列化是一个补充过程,允许将这个二进制流转换回对象。

Serialization is a way to represent a java object as a series of bytes. Its just a format nothing more. A "build-in" java serialization is a class that provides an API for conversion of the java object to a series of bytes. That's it. Of course, deserialization is a "complementary" process that allows to convert this binary stream back to the object.

序列化/反序列化本身与发送无关通过网络的事情。它只是方便发送一个二进制流,可以通过序列化从对象创建。

The serialization/deserialization itself has nothing to do with the "sending over the network" thing. Its just convenient to send a binary stream that can be created from the object with the serialization.

更多的是,有时内置的序列化不是获取的最佳方式二进制流,因为有时可以通过使用更少的字节来转换对象。

Even more, sometimes the built-in serialization is not an optimal way to get the binary stream, because sometimes the object can be converted by using less bytes.

所以你可以使用自定义协议,为序列化提供自己的自定义(例如,可外部化

So you can use you're custom protocol, provide your own customization for serialization (for example, Externalizable)

甚至使用第三方库,如 Apache Avro

or even use third party libraries like Apache Avro

我认为这有效地回答了你的两个问题:

I think this effectively answers both of your questions:


  1. 你可以转非序列化对象(我猜是那个没有实现Serializable接口的对象)如果你想要自己的字节序列(字节流),然后通过网络发送,存储在二进制文件中,无论如何。
    当然,您必须了解如何阅读这种二进制格式以便转换回来。

  1. You can turn the non-serialized object (I guess the one that doesn't implement "Serializable" interface) to the series of bytes (byte stream) by yourself if you want and then send it over the network, store in a binary file, whatsoever. Of course you'll have to understand how to read this binary format for converting back.

因为序列化只是转换协议而不是一个存储相关的东西,答案是显而易见的。

Since serialization is just a protocol of conversion and not a "storage related thing", the answer is obvious.

希望这有帮助。

这篇关于Java序列化对象与非序列化对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆