# Class: BinaryObject

## BinaryObject(typeName)

Class representing a complex Ignite object in the binary form.

It corresponds to COMPOSITE_TYPE.COMPLEX_OBJECT ObjectType.COMPOSITE_TYPE, has mandatory type Id, which corresponds to a name of the complex type, and includes optional fields.

An instance of the BinaryObject can be obtained/created by the following ways:

- returned by the client when a complex object is received from Ignite cache and is not deserialized to another JavaScript object.
- created using the public constructor. Fields may be added to such an instance using setField() method.
- created from a JavaScript object using static fromObject() method.

## Constructor

#### new BinaryObject(typeName)

Creates an instance of the BinaryObject without any fields.

Fields may be added later using setField() method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`typeName` | string | name of the complex type to generate the type Id.

Source:
  - BinaryObject.js, line 61

### Methods

#### (async, static) fromObject(jsObject, complexObjectTypeopt) → {BinaryObject}

Creates an instance of the BinaryObject from the specified instance of JavaScript Object.

All fields of the JavaScript Object instance with their values are added to the BinaryObject. Fields may be added or removed later using setField() and removeField() methods.

If complexObjectType parameter is specified, then the type Id is taken from it. Otherwise, the type Id is generated from the name of the JavaScript Object.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`jsObject` | object |  |  | instance of JavaScript Object which adds and initializes the fields of the BinaryObject instance.
`complexObjectType` | ComplexObjectType | <optional> | null | instance of complex type definition which specifies non-standard mapping of the fields of the BinaryObject instance to/from the Ignite types.

Source:
  - BinaryObject.js, line 105

##### Throws:

if error.

Type
  IgniteClientError

##### Returns:

- new BinaryObject instance.

Type
  BinaryObject

#### (async) getField(fieldName, fieldTypeopt) → {*}

Returns a value of the specified field.

Optionally, specifies a type of the field. If the type is not specified then the Ignite client will try to make automatic mapping between JavaScript types and Ignite object types - according to the mapping table defined in the description of the ObjectType class.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`fieldName` | string |  |  | name of the field.
`fieldType` | ObjectType.PRIMITIVE_TYPE | CompositeType | <optional> | null | type of the field: either a type code of primitive (simple) type or an instance of class representing non-primitive (composite) type or null (or not specified) that means the type is not specified.

Source:
  - BinaryObject.js, line 209

##### Throws:

if error.

Type
  IgniteClientError

##### Returns:

- value of the field or JavaScript undefined if the field does not exist.

Type
  *

#### getFieldNames() → {Array.<string>}

Returns names of all fields of this BinaryObject instance.

Source:
  - BinaryObject.js, line 261

##### Throws:

if error.

Type
  IgniteClientError

##### Returns:

- names of all fields.

Type
  Array.<string>

#### getTypeName() → {string}

Returns type name of this BinaryObject instance.

Source:
  - BinaryObject.js, line 250

##### Returns:

- type name.

Type
  string

#### hasField(fieldName) → {boolean}

Checks if the specified field exists in this BinaryObject instance.

##### Parameters:

Name | Type | Description
--- | --- | ---
`fieldName` | string | name of the field.

Source:
  - BinaryObject.js, line 184

##### Throws:

if error.

Type
  IgniteClientError

##### Returns:

- true if exists, false otherwise.

Type
  boolean

#### removeField(fieldName) → {BinaryObject}

Removes the specified field. Does nothing if the field does not exist.

##### Parameters:

Name | Type | Description
--- | --- | ---
`fieldName` | string | name of the field.

Source:
  - BinaryObject.js, line 167

##### Throws:

if error.

Type
  IgniteClientError

##### Returns:

- the same instance of BinaryObject

Type
  BinaryObject

#### setField(fieldName, fieldValue, fieldTypeopt) → {BinaryObject}

Sets the new value of the specified field. Adds the specified field, if it did not exist before.

Optionally, specifies a type of the field. If the type is not specified then during operations the Ignite client will try to make automatic mapping between JavaScript types and Ignite object types - according to the mapping table defined in the description of the ObjectType class.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`fieldName` | string |  |  | name of the field.
`fieldValue` | * |  |  | new value of the field.
`fieldType` | ObjectType.PRIMITIVE_TYPE | CompositeType | <optional> | null | type of the field: either a type code of primitive (simple) type or an instance of class representing non-primitive (composite) type or null (or not specified) that means the type is not specified.

Source:
  - BinaryObject.js, line 148

##### Throws:

if error.

Type
  IgniteClientError

##### Returns:

- the same instance of BinaryObject

Type
  BinaryObject

#### (async) toObject(complexObjectType) → {object}

Deserializes this BinaryObject instance into an instance of the specified complex object type.

##### Parameters:

Name | Type | Description
--- | --- | ---
`complexObjectType` | ComplexObjectType | instance of class representing complex object type.

Source:
  - BinaryObject.js, line 227

##### Throws:

if error.

Type
  IgniteClientError

##### Returns:

- instance of the JavaScript object which corresponds to the specified complex object type.

Type
  object