ObjectWritable (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.io, class: ObjectWritable

Package org.apache.hadoop.io

# Class ObjectWritable

java.lang.Object
org.apache.hadoop.io.ObjectWritable

All Implemented Interfaces:
  `Configurable`, `Writable`

@Public @Stable public class ObjectWritable extends Object implements Writable, Configurable
A polymorphic Writable that writes an instance with it's class name. Handles arrays, strings and primitive types without a Writable wrapper.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ObjectWritable()`
  `ObjectWritable(Class declaredClass, Object instance)`
  `ObjectWritable(Object instance)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `get()`
  Return the instance, or null if none.
  `Configuration`
  `getConf()`
  Return the configuration used by this object.
  `Class`
  `getDeclaredClass()`
  Return the class this is meant to be.
  `static Class<?>`
  `loadClass(Configuration conf, String className)`
  Find and load the class with given name `className` by first finding it in the specified `conf`.
  `void`
  `readFields(DataInput in)`
  Deserialize the fields of this object from `in`.
  `static Object`
  `readObject(DataInput in, Configuration conf)`
  Read a `Writable`, `String`, primitive type, or an array of the preceding.
  `static Object`
  `readObject(DataInput in, ObjectWritable objectWritable, Configuration conf)`
  Read a `Writable`, `String`, primitive type, or an array of the preceding.
  `void`
  `set(Object instance)`
  Reset the instance.
  `void`
  `setConf(Configuration conf)`
  Set the configuration to be used by this object.
  `String`
  `toString()`
  `void`
  `write(DataOutput out)`
  Serialize the fields of this object to `out`.
  `static void`
  `writeObject(DataOutput out, Object instance, Class declaredClass, Configuration conf)`
  Write a `Writable`, `String`, primitive type, or an array of the preceding.
  `static void`
  `writeObject(DataOutput out, Object instance, Class declaredClass, Configuration conf, boolean allowCompactArrays)`
  Write a `Writable`, `String`, primitive type, or an array of the preceding.

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

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

- ## Constructor Details

  - ### ObjectWritable

    public ObjectWritable()

  - ### ObjectWritable

    public ObjectWritable(Object instance)

  - ### ObjectWritable

    public ObjectWritable(Class declaredClass, Object instance)

- ## Method Details

  - ### get

    public Object get()
    Return the instance, or null if none.
    Returns:
      the instance, or null if none.

  - ### getDeclaredClass

    public Class getDeclaredClass()
    Return the class this is meant to be.
    Returns:
      the class this is meant to be.

  - ### set

    public void set(Object instance)
    Reset the instance.
    Parameters:
      `instance` - instance.

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### readFields

    public void readFields(DataInput in) throws IOException
    Description copied from interface: `Writable`
    Deserialize the fields of this object from `in`.

    For efficiency, implementations should attempt to re-use storage in the existing object where possible.

    Specified by:
      `readFields` in interface `Writable`
    Parameters:
      `in` - `DataInput` to deseriablize this object from.
    Throws:
      `IOException` - any other problem for readFields.

  - ### write

    public void write(DataOutput out) throws IOException
    Description copied from interface: `Writable`
    Serialize the fields of this object to `out`.
    Specified by:
      `write` in interface `Writable`
    Parameters:
      `out` - `DataOuput` to serialize this object into.
    Throws:
      `IOException` - any other problem for write.

  - ### writeObject

    public static void writeObject(DataOutput out, Object instance, Class declaredClass, Configuration conf) throws IOException
    Write a `Writable`, `String`, primitive type, or an array of the preceding.
    Parameters:
      `out` - DataOutput.
      `instance` - instance.
      `conf` - Configuration.
      `declaredClass` - declaredClass.
    Throws:
      `IOException` - raised on errors performing I/O.

  - ### writeObject

    public static void writeObject(DataOutput out, Object instance, Class declaredClass, Configuration conf, boolean allowCompactArrays) throws IOException
    Write a `Writable`, `String`, primitive type, or an array of the preceding.
    Parameters:
      `allowCompactArrays` - - set true for RPC and internal or intra-cluster usages. Set false for inter-cluster, File, and other persisted output usages, to preserve the ability to interchange files with other clusters that may not be running the same version of software. Sometime in ~2013 we can consider removing this parameter and always using the compact format.
      `conf` - configuration.
      `out` - dataoutput.
      `declaredClass` - declaredClass.
      `instance` - instance.
    Throws:
      `IOException` - raised on errors performing I/O.

  - ### readObject

    public static Object readObject(DataInput in, Configuration conf) throws IOException
    Read a `Writable`, `String`, primitive type, or an array of the preceding.
    Parameters:
      `conf` - configuration.
      `in` - DataInput.
    Returns:
      Object.
    Throws:
      `IOException` - raised on errors performing I/O.

  - ### readObject

    public static Object readObject(DataInput in, ObjectWritable objectWritable, Configuration conf) throws IOException
    Read a `Writable`, `String`, primitive type, or an array of the preceding.
    Parameters:
      `in` - DataInput.
      `objectWritable` - objectWritable.
      `conf` - configuration.
    Returns:
      Object.
    Throws:
      `IOException` - raised on errors performing I/O.

  - ### loadClass

    public static Class<?> loadClass(Configuration conf, String className)
    Find and load the class with given name `className` by first finding it in the specified `conf`. If the specified `conf` is null, try load it directly.
    Parameters:
      `conf` - configuration.
      `className` - classname.
    Returns:
      Class.

  - ### setConf

    public void setConf(Configuration conf)
    Description copied from interface: `Configurable`
    Set the configuration to be used by this object.
    Specified by:
      `setConf` in interface `Configurable`
    Parameters:
      `conf` - configuration to be used

  - ### getConf

    public Configuration getConf()
    Description copied from interface: `Configurable`
    Return the configuration used by this object.
    Specified by:
      `getConf` in interface `Configurable`
    Returns:
      Configuration