简体   繁体   English

已编组和未编组的对象

[英]object marshalled and unmarshalled

What is meant by object marshaling and unmarshaling?对象编组和解组是什么意思? What is the impact on object state when the above operation happens, ie the effect of serialization on hashCode and equals ?上述操作发生时对对象状态有什么影响,即序列化对hashCodeequals

To marshall an object is to convert it into a form suitable for serialised storage or transmission;编组对象是将其转换为适合序列化存储或传输的形式; that is, to convert it from its native form within the JVM's memory, into a form that could be sent down a wire, inserted into a file/database, etc. The specifics will vary depending on the form of marshalling involved;也就是说,将其从 JVM 内存中的本机形式转换为可以通过线路发送、插入文件/数据库等的形式。具体取决于所涉及的编组形式; Java's default serialisation mechanism is one way, but converting the object into an XML or JSON representation are equally valid. Java 的默认序列化机制是一种方式,但将对象转换为 XML 或 JSON 表示同样有效。

Unmarshalling is just the reverse/other side of this process;解组只是这个过程的反面/另一面; taking a representation of the object created by marshalling, and using it to reconstitute an object instance within the JVM.获取由编组创建的对象的表示,并使用它在 JVM 中重建对象实例。


I'm not sure exactly what you mean by the other part of your question, to be honest.老实说,我不确定你问题的另一部分到底是什么意思。 The original object is typically not changed by marshalling (which is conceptually a read-only operation, like taking a copy).原始对象通常不会被编组更改(这在概念上是只读操作,如复制)。 So it's hashcode, etc., would remain unchanged.所以它的哈希码等将保持不变。

An unmarshalled copy of the object will by definition have the same logical state as the original object (that's the point of the marshalling after all, to be able to reproduce an equivalent object).根据定义,对象的未编组副本将具有与原始对象相同的逻辑状态(毕竟这是编组的重点,以便能够重现等效对象)。 So in that respect its state, ie the values of its fields, is the same.所以在这方面它的状态,即它的字段的值,是相同的。 However, if the hashcode depends on environmental factors - such as the hostname of the machine, or the memory address where the instance is stored - then it might of course report something different.但是,如果哈希码取决于环境因素——例如机器的主机名或存储实例的内存地址——那么它当然可能会报告不同的东西。 This is particularly relevant with the default Object.hashCode() implementation, whereby the memory location of an object matters.这与默认的Object.hashCode()实现特别相关,其中对象的内存位置很重要。 (But then this is not related to marshalling; taking a "perfect copy" of an object within the same JVM by any means would still lead to a different hashcode in this case.) (但这与编组无关;在这种情况下,以任何方式在同一 JVM 中获取对象的“完美副本”仍然会导致不同的哈希码。)

marshalling means producing a stream of byte which contain enough information to be able to re-build the object.编组意味着生成一个字节流,其中包含足够的信息以能够重新构建对象。

This has no impact on the original object, it is a read-only operation.这对原始对象没有影响,它是一个只读操作。 Unmarshalling resulting in creating another, unrelated object (typically).解组导致创建另一个不相关的对象(通常)。

The copy, is likely to have the same hashCode() and be equals() == true and compareTo() == 0 (assuming its Comparable).副本很可能具有相同的hashCode()并且是equals() == truecompareTo() == 0 (假设它的 Comparable )。

Marshaling is almost the same as serialization.编组几乎与序列化相同。 The difference (in Java context) is in remote object handling, as specified in rfc2713 .区别(在 Java 上下文中)在于远程对象处理,如rfc2713 中所指定。

As for hash code value: it depends on how the object calculates its hash code.至于哈希码值:这取决于对象如何计算其哈希码。 If it's calculated from the fields only, then it obviously is same as the unmarshaled object is equal to the original one.如果仅从字段计算,则显然与未编组的对象等于原始对象相同 But if it uses Object 's original hashCode , then it's whatever the JVM happens to give to that object, and will vary from instance to instance.但是,如果它使用Object的原始hashCode ,那么它就是 JVM 碰巧赋予该对象的任何内容,并且会因实例而异。

In C++, if you generically make the hash-code from the memory-block in which the object is stored, it will likely be different in unmarshaled objects.在 C++ 中,如果您一般从存储对象的内存块中生成哈希码,则在未编组的对象中可能会有所不同。

First pointer values are different.第一个指针值不同。 Second the vtbl pointer is different due to relocation of the binary by the system loader.其次由于系统加载程序对二进制文件的重定位, vtbl 指针是不同的。

Its for saving objects or sending them to another for example VM in the Java world.它用于保存对象或将它们发送到另一个例如 Java 世界中的 VM。 The object will be reconstructed after marshaling to be the same if you have marshaled all information.如果您已编组所有信息,则在编组后对象将被重建为相同。

You can for example mark fields so that they are lost in serialization and then you can't recreate the object fully.例如,您可以标记字段,以便它们在序列化中丢失,然后您无法完全重新创建对象。

Most probably the state is lost , and this is due too that you usually don't serialize the state but only the data the bean holds.很可能状态丢失了,这也是由于您通常不序列化状态,而是只序列化 bean 持有的数据。 eg you serialize the field address .例如,您序列化字段地址 you don't serialize the state "2 person currently looking at the object".您不会序列化状态“当前正在查看对象的 2 个人”。

编组是将对象中存在的数据转换为 xml 格式并以 xml 格式查看它,而解组与将 xml 文件转换为对象相反

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JAXB重用未编组的对象 - JAXB reusing unmarshalled object 如何使用一个单独的routebuilder映射2个经过不同编组和解组的服务? - How do I map 2 services that are marshalled and unmarshalled differently using one single routebuilder? 获取JAXB编组的NullPointerException处理对象模型 - Getting NullPointerException processing object model unmarshalled by JAXB 如何在Camel中将非编组对象设置为交换属性 - How to set an unmarshalled object to an exchange property in Camel 如果未设置命名空间前缀,则解组对象为 null - Unmarshalled object is null if namespace prefix is not set 使用JAXB将Marshalled对象附加到XML文件中 - Append Marshalled Object Into XML File Using JAXB 使用泛型时,RestClient不会返回确切的未编组对象 - RestClient is not returning exact unmarshalled object when Generics are used 错误:未编组的 object 是骆驼 XML 文件中不受支持的类型 - ERROR: Unmarshalled object is an unsupported type in camel XML file 将xml发布到spring REST端点不会被解组到相关的Java对象中 - posting xml to a spring REST endpoint is not getting unmarshalled into the relevant Java object 使用MOxy进行xml绑定并返回null的未编组对象 - Using MOxy for xml binding returning null unmarshalled object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM