toJson method

Map<String, String> toJson()

Converts this comment to a JSON map.

Only includes fields that should be sent to the server. Excludes computed properties like initials and UI-only properties.

Returns a map with the following fields:

  • id: String
  • parentId: String? (only if not null)
  • content: String
  • entityId: String
  • userId: String
  • username: String

Note: date, likeCount, and replyCount are excluded as they are typically managed by the server.

Implementation

Map<String, String> toJson() {
  return {
    'id': id,
    //'date': date.toIso8601String(),
    if (parentId != null) 'parentId': parentId!,
    'content': content,
    'entityId': entityId,
    'userId': userId,
    'username': username,
    //'likeCount': likeCount,
    //'replyCount': replyCount,
  };
}