org.apache.ignite.marshaller

## Interface Marshaller

All Known Implementing Classes:
  AbstractMarshaller, BinaryMarshaller, JdkMarshaller, OptimizedMarshaller

    public interface Marshaller

`Marshaller` allows to marshal or unmarshal objects in grid. It provides serialization/deserialization mechanism for all instances that are sent across networks or are otherwise serialized.

Ignite provides the following `Marshaller` implementations:

- `OptimizedMarshaller` - default
- `JdkMarshaller`

Below are examples of marshaller configuration, usage, and injection into tasks, jobs, and SPI's.

## Java Example

`Marshaller` can be explicitly configured in code.

     JdkMarshaller marshaller = new JdkMarshaller();

     IgniteConfiguration cfg = new IgniteConfiguration();

     // Override marshaller.
     cfg.setMarshaller(marshaller);

     // Starts grid.
     G.start(cfg);

## Spring Example

Marshaller can be configured from Spring XML configuration file:

     <bean id="grid.custom.cfg" class="org.apache.ignite.configuration.IgniteConfiguration" singleton="true">
         ...
         <property name="marshaller">
             <bean class="org.apache.ignite.marshaller.jdk.JdkMarshaller"/>
         </property>
         ...
     </bean>

For information about Spring framework visit www.springframework.org

### Method Summary

Methods
`byte[]` `marshal(Object obj)` Marshals object to byte array.
`void` `marshal(Object obj, OutputStream out)` Marshals object to the output stream.
`void` `setContext(MarshallerContext ctx)` Sets marshaller context.
`<T> T` `unmarshal(byte[] arr, ClassLoader clsLdr)` Unmarshals object from byte array using given class loader.
`<T> T` `unmarshal(InputStream in, ClassLoader clsLdr)` Unmarshals object from the input stream using given class loader.

### Method Detail

#### setContext

    void setContext(MarshallerContext ctx)

Sets marshaller context.

Parameters:
  `ctx` - Marshaller context.

#### marshal

    void marshal(@Nullable
               Object obj,
               OutputStream out)
                 throws IgniteCheckedException

Marshals object to the output stream. This method should not close given output stream.

Parameters:
  `obj` - Object to marshal.
  `out` - Output stream to marshal into.
Throws:
  `IgniteCheckedException` - If marshalling failed.

#### marshal

    byte[] marshal(@Nullable
                 Object obj)
                   throws IgniteCheckedException

Marshals object to byte array.

Parameters:
  `obj` - Object to marshal.
Returns:
  Byte array.
Throws:
  `IgniteCheckedException` - If marshalling failed.

#### unmarshal

    <T> T unmarshal(InputStream in,
                  @Nullable
                  ClassLoader clsLdr)
                throws IgniteCheckedException

Unmarshals object from the input stream using given class loader. This method should not close given input stream.

Type Parameters:
  `T` - Type of unmarshalled object.
Parameters:
  `in` - Input stream.
  `clsLdr` - Class loader to use.
Returns:
  Unmarshalled object.
Throws:
  `IgniteCheckedException` - If unmarshalling failed.

#### unmarshal

    <T> T unmarshal(byte[] arr,
                  @Nullable
                  ClassLoader clsLdr)
                throws IgniteCheckedException

Unmarshals object from byte array using given class loader.

Type Parameters:
  `T` - Type of unmarshalled object.
Parameters:
  `arr` - Byte array.
  `clsLdr` - Class loader to use.
Returns:
  Unmarshalled object.
Throws:
  `IgniteCheckedException` - If unmarshalling failed.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.5.0.final
Release Date | : December 29 2015