# Stub vs Skeleton, Marshalling vs Serialization in Java

In 
Java
Published 2022-12-03

Let's think that we have a Java client which must call a Java server (service). Each JVM (on the client side and on the service side) is working with Java objects.

When the client wants to send a request to the server, the call is done using an XML/JSON/text format. The service receive the XML/JSON/text format and convert it to a Java object. When the response is sent back, the server will convert back the response Java object to an XML/JSON/text format and sent it to the client. The client will receive the XML/JSON/text format and convert it to a Java object.

When you have a Java object, text, anything which must be put in memory, on disk or transmitted on the network, we need to have a binary representation for that object, text, etc.

The operation of transforming an object to a binary representation (stream of bytes) is named serialization. This stream of bytes can then be stored in a file or transmitted over a network. The opposite action is the deserialization.

Locally, we keep the information about the structure of the data, and it is possible to transform back from binary to an object.

But imagine you send remote a binary representation to a server (which happens always because the network is used), and you want that remote server to deserialize that binary representation. This is not possible, without giving it the way how the object could be created (the codebase). In this case, the serialization becomes marshalling. The opposite action is the unmarshalling.