为什么传输对象需要实现Serialized?

发布于 2024-08-25 10:15:25 字数 164 浏览 8 评论 0原文

今天我意识到,多年来我一直盲目地遵循这个要求,却从未真正问过为什么。今天,我在从头开始创建的模型对象中遇到了 NotSerializedException,我意识到已经足够了。

有人告诉我这是因为负载平衡服务器之间的会话复制,但我知道我在会话范围内看到了其他未实现可序列化的对象。这是真正的原因吗?

I realized today that I have blindly just followed this requirement for years without ever really asking why. Today, I ran across a NotSerializableException with a model object I created from scratch and I realized enough is enough.

I was told this was because of session replication between load-balanced servers, but I know I've seen other objects at session scope that do not implement Serializable. Is this the real reason?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱,才寂寞 2024-09-01 10:15:25

这才是真正的原因。它在实践中是否真正重要完全取决于 Web 服务器或应用程序服务器实际上是否会序列化对象(或验证它是否可序列化,但实际上唯一的方法就是实际序列化它)。

大多数应用程序服务器(至少)可以选择不严格限制。如果您不使用实际共享状态的负载平衡服务器,那么您可能已经看到它没有问题。

It is the real reason. If it will actually matter in practice depends entirely on if the web server or application server will in fact serialize the object (or validate that it is serializable, but realistically the only way to do that is to actually serialize it).

Most application servers have the option (at least) of not being strict about it. If you don't use load balanced servers that actually share state, then you might have seen it without a problem.

爱,才寂寞 2024-09-01 10:15:25

因为为了通过线路传输,它们需要可序列化为可以放在线路上的形式。

像二进制、xml、Json 或类似文件

有更多信息… 应该任何域对象都不能序列化?

Because in order to be transferred across a wire they need to be serialisable to a form that can be put on the wire.

Like binary, or xml, Json, or simillar

There's more info here... Should any domain object, not be serializable?

够运 2024-09-01 10:15:25

我认为这个概念类似于被问到,
为什么固体食物必须先咀嚼才能吞咽消化。
但当然,不同之处在于消化好的东西无论如何都不能反序列化。

我记得使用 Sun RPC(现在称为 ONC RPC)来执行 XDR 编码
因为计算机平台/系统以各自的形式表示其数据。例如,
大端与小端。

但是JVM无论机器都是big-endian,所以endianness不应该成为一个理由。

计算机内存中的数据结构具有指针,并且对象的所有元素可能不位于连续的内存块上。但是,当您通过 I/O 将对象传递到另一个系统时,您无法传递该对象的内存分配。

对象在存储到数据库之前需要进行序列化,因为您不希望也不希望复制动态变化的系统内存排列。

我们网络上的数据表示层都是基于比特流的。因此,当您希望将数据从一个系统传递到另一个系统时,必须将内存中表示的维度数据转换为可以通过网络逐字节传输的数据。实际上,一点一点地进行,并且通常会经过压缩和安全加密。压缩和加密例程是 oo 结构盲的,并且假定比特流。网络交换机是 oo 结构盲的。网络传输连比特都看不到。这些比特被编码成传输信号,该信号通常是模拟正弦波,然后进行调制。这些过程不适用于面向对象结构数据的多维/分层模式。

我想您可以执行对象级混淆和加密,但您仍然必须允许系统将它们转换为比特流,方法是首先将它们转换为字符流。

编组是指牧羊人有一群羊,并通过一座单羊桥将它们编组到浑水之上。因此,编组器必须将我们的对象编组为写入引用的串行模式,以便当信息羊群从桥的另一端出现时,我们能够通过共轭解组器将它们重新组装回其分层模式。在我们的例子中,我们的羊不仅仅通过桥梁进行编组,还通过狭窄且不稳定的蜿蜒曲折和山体滑坡,网络传输设备在每个转弯处都存储编组羊的副本,以确保它们能够在发生任何情况时重新发送副本羊掉进了峡谷。

I think the concept is akin to being asked,
why must solid food be chewed down before being swallowed for digestion.
But of course, the difference is that digested good cannot be in anyway deserialized.

I remember using Sun RPC (nowadays called ONC RPC) which performs XDR encoding
because computer platforms/systems represent their data in their respective forms. For example,
big endian vs small endian.

But the JVM, regardless of machine is big-endian, so endianness should not be a reason.

Data structure in computer memory has pointers and all the elements of an object may not sit on a contiguous memory block. However, when you pass an object thro i/o to another system, you cannot pass the memory distribution of that object.

An Object needs to be serialized before being stored in a database because you do not and cannot wish to replicate the dynamically changing arrangement of system memory.

Our data representation layer on the networks are all bit stream-based. Therefore, when you wish to pass data from one system to another, you have to convert the dimensional data represented in memory to one that can be streamed thro the networks byte by byte. Actually, bit by bit, and which often goes thro compression and security encryption. Compression and encryption routines are oo-structure-blind and bit streams are presumed. Network switches are oo-structure-blind. Network transmission does not even see bits. The bits are encoded into a transmission signal that is often analogue sinusoids and then modulated. These processes do not work on multidimensional/hierarchical schemata of oo-structured data.

I guess you could perform object level obfuscation and encryption, yet you still have to allow the system to convert those to bit streams, by converting them to char streams first.

Marshalling is when the shepherd has a herd of sheep and marshalls them thro a single-sheep bridge over troubled waters. Therefore, a marshaller has to marshall our objects into serial schemata with references written in, so that when the flock of information sheep emerge from the other end of the bridge, we are able to reassemble them back into its hierarchical schemata by the conjugate-demarshaller. In our case, our sheep is not marshalled thro just a bridge but thro narrow and precarious windings and landslides where the network transmission equipment at each turn stores a copy of the marshalled sheep to ensure they are able to resend the copy in case any of the sheep has fallen thro a ravine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文