CockpitDocumentResource.fromJson constructor

CockpitDocumentResource.fromJson(
  1. Object? value, {
  2. String path = r'$',
  3. CockpitDecodePolicy decodePolicy = CockpitDecodePolicy.requests,
})

Decodes a CockpitDocumentResource from a JSON object.

Implementation

factory CockpitDocumentResource.fromJson(
  Object? value, {
  String path = r'$',
  CockpitDecodePolicy decodePolicy = CockpitDecodePolicy.requests,
}) {
  final json = CockpitFoundationValueReader.object(value, path);
  const fields = <String>{
    'documentId',
    'workspaceId',
    'relativePath',
    'sha256',
    'modifiedAt',
    'kind',
    'authoredId',
    'title',
    'cases',
  };
  CockpitFoundationValueReader.keys(
    json,
    fields,
    path,
    required: fields.difference(const <String>{'authoredId', 'title'}),
    policy: decodePolicy,
  );
  final rawCases = CockpitFoundationValueReader.list(
    json['cases'],
    '$path.cases',
  );
  return CockpitDocumentResource(
    documentId: CockpitFoundationValueReader.id(
      json['documentId'],
      '$path.documentId',
    ),
    workspaceId: CockpitFoundationValueReader.id(
      json['workspaceId'],
      '$path.workspaceId',
    ),
    relativePath: CockpitFoundationValueReader.relativePath(
      json['relativePath'],
      '$path.relativePath',
    ),
    sha256: CockpitFoundationValueReader.sha256(
      json['sha256'],
      '$path.sha256',
    ),
    modifiedAt: CockpitFoundationValueReader.dateTime(
      json['modifiedAt'],
      '$path.modifiedAt',
    ),
    kind: _documentKind(json['kind'], '$path.kind'),
    authoredId: json['authoredId'] == null
        ? null
        : CockpitFoundationValueReader.id(
            json['authoredId'],
            '$path.authoredId',
          ),
    title: CockpitFoundationValueReader.optionalString(
      json['title'],
      '$path.title',
      maximum: 256,
    ),
    cases: <CockpitCaseIndexEntry>[
      for (var index = 0; index < rawCases.length; index += 1)
        CockpitCaseIndexEntry.fromJson(
          rawCases[index],
          path: '$path.cases[$index]',
          decodePolicy: decodePolicy,
        ),
    ],
  );
}