org.apache.ignite.internal.portable.api

## Class PortableMarshaller

- java.lang.Object
- - org.apache.ignite.marshaller.AbstractMarshaller
  - - org.apache.ignite.internal.portable.api.PortableMarshaller

All Implemented Interfaces:
  Marshaller

    public class PortableMarshaller
    extends AbstractMarshaller

Implementation of `Marshaller` that lets to serialize and deserialize all objects in the portable format.

`PortableMarshaller` is tested only on Java HotSpot VM on other VMs it could yield unexpected results.

# Configuration

## Mandatory

This marshaller has no mandatory configuration parameters.

## Java Example

     PortableMarshaller marshaller = new PortableMarshaller();

     IgniteConfiguration cfg = new IgniteConfiguration();

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

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

## Spring Example

PortableMarshaller 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.internal.portable.api.PortableMarshaller">
                ...
             </bean>
         </property>
         ...
     </bean>

For information about Spring framework visit www.springframework.org

### Field Summary

Fields
`static PortableProtocolVersion` `DFLT_PORTABLE_PROTO_VER` Default portable protocol version.

### Fields inherited from class org.apache.ignite.marshaller.AbstractMarshaller

`ctx, DFLT_BUFFER_SIZE`

### Constructor Summary

Constructors
Constructor and Description
`PortableMarshaller()`

### Method Summary

Methods
`Collection<String>` `getClassNames()` Gets class names.
`MarshallerContext` `getContext()` Returns currently set `MarshallerContext`.
`PortableIdMapper` `getIdMapper()` Gets ID mapper.
`PortableProtocolVersion` `getProtocolVersion()` Gets portable protocol version.
`PortableSerializer` `getSerializer()` Gets serializer.
`Collection<PortableTypeConfiguration>` `getTypeConfigurations()` Gets types configuration.
`boolean` `isConvertStringToBytes()` Gets strings must be converted to or from bytes using UTF-8 encoding.
`boolean` `isKeepDeserialized()` If `true`, `PortableObject` will cache deserialized instance after `PortableObject.deserialize()` is called.
`boolean` `isMetaDataEnabled()` If `true`, meta data will be collected or all types.
`boolean` `isUseTimestamp()` If `true` then date values converted to `Timestamp` on deserialization.
`byte[]` `marshal(Object obj)` Marshals object to byte array.
`void` `marshal(Object obj, OutputStream out)` Marshals object to the output stream.
`void` `setClassNames(Collection<String> clsNames)` Sets class names of portable objects explicitly.
`void` `setConvertStringToBytes(boolean convertString)` Sets strings must be converted to or from bytes using UTF-8 encoding.
`void` `setIdMapper(PortableIdMapper idMapper)` Sets ID mapper.
`void` `setKeepDeserialized(boolean keepDeserialized)`
`void` `setMetaDataEnabled(boolean metaDataEnabled)`
`void` `setProtocolVersion(PortableProtocolVersion protoVer)` Sets portable protocol version.
`void` `setSerializer(PortableSerializer serializer)` Sets serializer.
`void` `setTypeConfigurations(Collection<PortableTypeConfiguration> typeCfgs)` Sets type configurations.
`void` `setUseTimestamp(boolean useTs)`
`<T> T` `unmarshal(byte[] bytes, ClassLoader clsLdr)` Unmarshals object from byte array using given class loader.
`<T> T` `unmarshal(InputStream in, ClassLoader clsLdr)` Unmarshals object from the output stream using given class loader.

### Methods inherited from class org.apache.ignite.marshaller.AbstractMarshaller

`setContext`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### DFLT_PORTABLE_PROTO_VER

    public static final PortableProtocolVersion DFLT_PORTABLE_PROTO_VER

Default portable protocol version.

### Constructor Detail

#### PortableMarshaller

    public PortableMarshaller()

### Method Detail

#### getClassNames

    public Collection<String> getClassNames()

Gets class names.

Returns:
  Class names.

#### setClassNames

    public void setClassNames(Collection<String> clsNames)

Sets class names of portable objects explicitly.

Parameters:
  `clsNames` - Class names.

#### getIdMapper

    public PortableIdMapper getIdMapper()

Gets ID mapper.

Returns:
  ID mapper.

#### setIdMapper

    public void setIdMapper(PortableIdMapper idMapper)

Sets ID mapper.

Parameters:
  `idMapper` - ID mapper.

#### getSerializer

    public PortableSerializer getSerializer()

Gets serializer.

Returns:
  Serializer.

#### setSerializer

    public void setSerializer(PortableSerializer serializer)

Sets serializer.

Parameters:
  `serializer` - Serializer.

#### getTypeConfigurations

    public Collection<PortableTypeConfiguration> getTypeConfigurations()

Gets types configuration.

Returns:
  Types configuration.

#### setTypeConfigurations

    public void setTypeConfigurations(Collection<PortableTypeConfiguration> typeCfgs)

Sets type configurations.

Parameters:
  `typeCfgs` - Type configurations.

#### isUseTimestamp

    public boolean isUseTimestamp()

If `true` then date values converted to `Timestamp` on deserialization.

Default value is `true`.

Returns:
  Flag indicating whether date values converted to `Timestamp` during unmarshalling.

#### setUseTimestamp

    public void setUseTimestamp(boolean useTs)

Parameters:
  `useTs` - Flag indicating whether date values converted to `Timestamp` during unmarshalling.

#### isConvertStringToBytes

    public boolean isConvertStringToBytes()

Gets strings must be converted to or from bytes using UTF-8 encoding.

Default value is `true`.

Returns:
  Flag indicating whether string must be converted to byte array using UTF-8 encoding.

#### setConvertStringToBytes

    public void setConvertStringToBytes(boolean convertString)

Sets strings must be converted to or from bytes using UTF-8 encoding.

Default value is `true`.

Parameters:
  `convertString` - Flag indicating whether string must be converted to byte array using UTF-8 encoding.

#### isMetaDataEnabled

    public boolean isMetaDataEnabled()

If `true`, meta data will be collected or all types. If you need to override this behaviour for some specific type, use `PortableTypeConfiguration.setMetaDataEnabled(Boolean)` method.

Default value if `true`.

Returns:
  Whether meta data is collected.

#### setMetaDataEnabled

    public void setMetaDataEnabled(boolean metaDataEnabled)

Parameters:
  `metaDataEnabled` - Whether meta data is collected.

#### isKeepDeserialized

    public boolean isKeepDeserialized()

If `true`, `PortableObject` will cache deserialized instance after `PortableObject.deserialize()` is called. All consequent calls of this method on the same instance of `PortableObject` will return that cached value without actually deserializing portable object. If you need to override this behaviour for some specific type, use `PortableTypeConfiguration.setKeepDeserialized(Boolean)` method.

Default value if `true`.

Returns:
  Whether deserialized value is kept.

#### setKeepDeserialized

    public void setKeepDeserialized(boolean keepDeserialized)

Parameters:
  `keepDeserialized` - Whether deserialized value is kept.

#### getProtocolVersion

    public PortableProtocolVersion getProtocolVersion()

Gets portable protocol version.

Defaults to `DFLT_PORTABLE_PROTO_VER`.

Returns:
  Portable protocol version.

#### setProtocolVersion

    public void setProtocolVersion(PortableProtocolVersion protoVer)

Sets portable protocol version.

Defaults to `DFLT_PORTABLE_PROTO_VER`.

Parameters:
  `protoVer` - Portable protocol version.

#### getContext

    public MarshallerContext getContext()

Returns currently set `MarshallerContext`.

Returns:
  Marshaller context.

#### marshal

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

Marshals object to byte array.

Specified by:
  `marshal` in interface `Marshaller`
Overrides:
  `marshal` in class `AbstractMarshaller`
Parameters:
  `obj` - Object to marshal.
Returns:
  Byte array.
Throws:
  `IgniteCheckedException` - If marshalling failed.

#### marshal

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

#### unmarshal

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

Unmarshals object from byte array using given class loader.

Specified by:
  `unmarshal` in interface `Marshaller`
Overrides:
  `unmarshal` in class `AbstractMarshaller`
Type Parameters:
  `T` - Type of unmarshalled object.
Parameters:
  `bytes` - Byte array.
  `clsLdr` - Class loader to use.
Returns:
  Unmarshalled object.
Throws:
  `IgniteCheckedException` - If unmarshalling failed.

#### unmarshal

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

Unmarshals object from the output 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.

2015 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 1.4.0
Release Date | : September 24 2015