Entity.fromJson constructor

Entity.fromJson(
  1. Object? j
)

Implementation

factory Entity.fromJson(Object? j) {
  final json = j as Map<String, Object?>;
  return Entity(
    name: switch (json['name']) {
      null => '',
      Object $1 => decodeString($1),
    },
    type: switch (json['type']) {
      null => Entity_Type.$default,
      Object $1 => Entity_Type.fromJson($1),
    },
    metadata: switch (json['metadata']) {
      null => {},
      Map<String, Object?> $1 => {
        for (final e in $1.entries)
          decodeString(e.key): decodeString(e.value),
      },
      _ => throw const FormatException('"metadata" is not an object'),
    },
    mentions: switch (json['mentions']) {
      null => [],
      List<Object?> $1 => [for (final i in $1) EntityMention.fromJson(i)],
      _ => throw const FormatException('"mentions" is not a list'),
    },
    sentiment: switch (json['sentiment']) {
      null => null,
      Object $1 => Sentiment.fromJson($1),
    },
  );
}