decodeInt method

int decodeInt(
  1. String jsonPath,
  2. Object? json
)
inherited

Decode a JSON object that is expected to be an integer. A string representation of an integer is also accepted.

Implementation

int decodeInt(String jsonPath, Object? json) {
  if (json is int) {
    return json;
  } else if (json is String) {
    var value = int.tryParse(json);
    if (value == null) {
      throw mismatch(jsonPath, 'int', json);
    }
    return value;
  }
  throw mismatch(jsonPath, 'int', json);
}