Class: JSONBuilder

JSONBuilder

new JSONBuilder()

This class helps to create JSON representation from a model. Usage:

  return new JSONBuilder()
    .appendIfDefined('inReplyToMessageId', this.inReplyToMessageId)
    .appendIfDefined('isUnread', this.isUnread)
    .appendIfDefined('isFlagged', this.isFlagged)
    .build();
Source:

Methods

append(name, value)

Will append the value to the building object, using the name as key.

Parameters:
Name Type Description
name String

The name to use as key.

value *

The value to append.

Source:
Returns:

this builder

appendDateIfDefined(name, dateopt)

If defined, it will append date to the building object as an ISO Date String, using name as the key.

Parameters:
Name Type Attributes Description
name String

The name to use as key.

date Date <optional>

The Date to append.

Source:
See:
Returns:

This JSONBuilder instance

appendIfDefined(name, valueopt)

If defined, it will append the value to the building object, using the name as key.

Parameters:
Name Type Attributes Description
name String

The name to use as key.

value * <optional>

The value to append.

Source:
Returns:

this builder

appendIfNotEmpty(name, valueopt)

If defined and not empty, it will append the value array to the building object, using the name as key.

Parameters:
Name Type Attributes Description
name String

The name to use as key.

value Array <optional>

The value to append.

Source:
Returns:

this builder

appendObject(name, value)

Will append the value object to the building object by recursively calling toJSONObject() on each child if an object.

Parameters:
Name Type Description
name String

The name to use as key.

value Array

The Object to append

Source:

build()

Source:
Returns:

an object with all appended values