fromJson static method

Annotation? fromJson(
  1. JsonValue jsonValue
)

Implementation

static Annotation? fromJson(JsonValue jsonValue) {
  final type = jsonValue.getObjectValueOrThrow('type').asStringOrThrow();
  switch (type) {
    case 'text':
      return AnnotationText(
        maxLength: jsonValue
            .getObjectValueOrThrow('maxLength')
            .asDoubleOrThrow()
            .toInt(),
      );
    case 'dateTime':
      return const AnnotationDateTime();
    case 'url':
      return const AnnotationUrl();
    case 'regexp':
      return AnnotationRegExp(
        RegExp(jsonValue.getObjectValueOrThrow('pattern').asStringOrThrow()),
      );
    default:
      return null;
  }
}