valueAsString<T extends String?> static method

T valueAsString<T extends String?>(
  1. Object? value
)

Implementation

static T valueAsString<T extends String?>(Object? value) {
  if (value is T) return value;
  if (value == null && _isNull<T>()) return null as T;
  if (value is List<int>) {
    final decode = StringUtils.tryDecode(value, type: StringEncoding.utf8);
    if (decode != null) {
      return decode as T;
    }
  }
  if (value is! String) {
    throw JSONHelperException("Failed to parse value as string.");
  }
  return value as T;
}