Class: SFSObject


SFSObject and SFSArray classes represent a platform-neutral, high level Java objects that abstract the data transport between client and server. They are used to respectively represent data in form of a map and a list; they can be nested and transport many different data types.

These objects provide high speed serialization using the default SmartFoxServer binary protocol and the types distinction grants a fine-grained size control of data sent over the network.

The following is a list of types supported by the SFSObject class:

  • null
  • boolean
  • byte (8 bit integer)
  • short (16 bit integer)
  • int (32 bit integer)
  • long (64 bit integer)
  • float (32 bit floating point number)
  • double (64 bit double precision number)
  • utf-string (UTF-8 encoded string, with length up to 32 KBytes)
  • text (UTF-8 encoded string, with length up to 2 GBytes)
  • boolean array
  • byte array
  • short array
  • int array
  • long array
  • float array
  • double array
  • utf-string array
  • SFSObject
  • SFSArray

SFSObjects and SFSArrays can be nested to create complex data structures.


  • For members of the SFSObject class, please refer to its Javadoc.
  • SFSObject key strings are limited to ASCII characters.
  • SFSObject string values support UTF-8 encoding.
  • In JavaScript, long integer numbers are limited to Number.MAX_SAFE_INTEGER (positive and negative, inclusive). This is inconsistent with the max and min Long values available in Java, which are down to -2^63 and up to (2^63)-1.

See also

new SFSObject()

Creates a new SFSObject instance.

In this simple example we create a new SFSObject to send the data of a combat vehicle to clients in a multiplayer game.
We use a single Byte (signed 8-bit) to send the small integer value representing the vehicle's id, a Short (signed 16-bit) for the larger health value and an array of Int to transmit the x/y position of the vehicle.

var sfso = new SFSObject();
sfso.putByte("id", 10);                 // the vehicle id
sfso.putShort("health", 5000);          // the vehicle current health
sfso.putIntArray("pos", [120,150]);     // the vehicle x,y position on the terrain, as a nested array
sfso.putUtfString("name", "Hurricane"); // the vehicle name