Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

object marshalled and unmarshalled

Tags:

java

What is meant by object marshaling and unmarshaling? What is the impact on object state when the above operation happens, i.e. the effect of serialization on hashCode and equals?

like image 256
Harshana Avatar asked Aug 31 '11 09:08

Harshana


People also ask

What is meant by marshalling and unmarshalling?

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.

What are marshalling and unmarshalling Where is it done?

Overview. Marshalling and unmarshalling is used both on the client and server side. On the server side it is used to map an incoming request to a Scala or Java object and to map a Scala or Java object to an outgoing response.

What is difference between serialization and marshalling?

Marshaling and serialization are loosely synonymous in the context of remote procedure call, but semantically different as a matter of intent. In particular, marshaling is about getting parameters from here to there, while serialization is about copying structured data to or from a primitive form such as a byte stream.

What is marshalling and Demarshalling in Java?

OOP Java. When an application wants to pass its memory objects across a network to another host or persist it to storage, the in-memory representation must be converted to a suitable format. This process is called marshalling and the revert operation is called demarshalling.


1 Answers

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.)

like image 50
Andrzej Doyle Avatar answered Sep 21 '22 03:09

Andrzej Doyle