Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JsonObject factory accepts null, but will throw when null is passed #1242

Open
ahmednfwela opened this issue May 15, 2023 · 1 comment
Open
Assignees
Labels

Comments

@ahmednfwela
Copy link
Contributor

the JsonObject factory accepts a nullable parameter, but if null is passed it will throw

/// Instantiates with [value], which must be a bool, a List, a Map, a num
/// or a String. Otherwise, an [ArgumentError] is thrown.
factory JsonObject(Object? value) {
  if (value is num) {
    return NumJsonObject(value);
  } else if (value is String) {
    return StringJsonObject(value);
  } else if (value is bool) {
    return BoolJsonObject(value);
  } else if (value is List<Object?>) {
    return ListJsonObject(value);
  } else if (value is Map<String, Object?>) {
    return MapJsonObject(value);
  } else if (value is Map) {
    // Allow wrong type map, check individual values.
    return MapJsonObject(value.cast());
  } else {
    throw ArgumentError.value(value, 'value',
        'Must be bool, List<Object?>, Map<String?, Object?>, num or String');
  }
}
@davidmorgan
Copy link
Collaborator

Thanks--I need to take another look at all the APIs to see if there are breaking changes worth making, I'll consider this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants