toJson method

Map<String, dynamic> toJson()

Serializes this Space into a json Map

Implementation

Map<String, dynamic> toJson() {
  final jsonMap = {
    'name': name,
    'id': id,
    'type': 'space',
    '_links': links.toJson(),
    if (key != null) 'key': key,
    if (category != null) 'belongsTo': category,
    if (color != null)
      'color':
          '#${color!.red.toRadixString(16)}${color!.green.toRadixString(16)}${color!.blue.toRadixString(16)}',
    if (icon != null) 'icon': icon,
    if (iconSet != null) 'iconset': iconSet,
  };

  if (embeddedGrids != null) {
    final embeddedMap =
        jsonMap['_embedded'] as Map<String, dynamic>? ?? <String, dynamic>{};
    embeddedMap['grids'] = embeddedGrids?.map((e) => e.toJson()).toList();

    jsonMap['_embedded'] = embeddedMap;
  }

  return jsonMap;
}