[id='store_as_binary']
= Storing Data in Binary Format
{brandname} can store data in its serialized form, in binary format, and then
either serialize or deserialize Java objects as needed. This behavior is also
referred to as lazy deserialization.

.Programmatic procedure

[source,java]
----
include::code_examples/StorageTypeBinary.java[]
----

.Declarative procedure

[source,xml,options="nowrap",subs=attributes+]
----
include::config_examples/memory_binary.xml[]
----

.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:{javadocroot}/org/infinispan/commons/marshall/WrappedBytes.html[org.infinispan.commons.marshall.WrappedBytes].
