object marshalled and unmarshalled
What is meant by object marshaling and unmarshaling? What is the impact on object state when the above operation hap开发者_运维技巧pens, i.e. the effect of serialization on hashCode
and equals
?
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; Java's default serialisation mechanism is one way, but converting the object into an XML or JSON representation are equally valid.
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.
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, i.e. 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. (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.)
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).
Marshaling is almost the same as serialization. The difference (in Java context) is in remote object handling, as specified in 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.
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.
First pointer values are different. Second the vtbl pointer is different due to relocation of the binary by the system loader.
Its for saving objects or sending them to another for example VM in the Java world. 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. e.g you serialize the field address. you don't serialize the state "2 person currently looking at the object".
Marshalling is converting the data present in an object into a an xml format and viewing it in an xml format and unmarshalling is reverse of it converting an xml file into an object
精彩评论