[id='storing_binary_objects-{context}']
= Storing Marshalled Java Objects
Java Hot Rod clients can handle Java objects that represent entities and
perform marshalling to serialize and deserialize objects into `byte[]` arrays.
C{plusplus}, C#, and Javascript Hot Rod clients can also handle objects in the
respective languages.

If you store entries in the cache as marshalled Java objects, you should
configure the cache with the MediaType of the marshalled storage.

.Procedure

. Specify the MediaType that matches your marshaller implementation.
+
* Protostream marshaller: Configure the MediaType as `application/x-protostream`.
* JBoss marshalling: Configure the MediaType as `application/x-jboss-marshalling`.
* Java serialization: Configure the MediaType as `application/x-java-serialized-object`.
+
. Configure your clients.

Because REST clients are most suitable for handling text formats, you should
use primitives such as `java.lang.String` for keys. Otherwise, REST clients
must handle keys as `bytes[]` using a supported binary encoding.

REST clients can read values for cache entries in XML or JSON format.

.Equality Considerations

When storing data in binary format, {brandname} uses the `WrappedBytes`
interface for keys and values. This wrapper class transparently takes care of
serialization and deserialization on demand, and internally may have a
reference to the object itself being wrapped, or the serialized, byte array
representation of the object. This has an effect on the behavior of equality,
which is important to note if you implement an `equals()` methods on keys.

The `equals()` method of the wrapper class either compares binary
representations (byte arrays) or delegates to the wrapped object instance's
`equals()` method, depending on whether both instances being compared are in
serialized or deserialized form at the time of comparison. If one of the
instances being compared is in one form and the other in another form, then one
instance is either serialized or deserialized.

.Reference

* link:{dev_docs}#marshalling[Marshalling Java Objects]
* link:{javadocroot}/org/infinispan/commons/marshall/WrappedBytes.html[org.infinispan.commons.marshall.WrappedBytes]
