get<V> method

V get<V>(
  1. DatumFieldSpec<E, V> field
)

The decoded value of field; throws SchemaReadException on a missing key (for non-nullable fields), a null value, or a decode failure.

Implementation

V get<V>(DatumFieldSpec<E, V> field) {
  final value = raw[field.name];
  if (value == null && !field.isNullable) {
    throw SchemaReadException(
      entity: schemaName,
      fieldName: field.name,
      expectedType: V,
      actualValue: null,
      cause: raw.containsKey(field.name) ? 'value is null' : 'key missing',
    );
  }
  try {
    return field.decode(value);
  } on SchemaReadException catch (error) {
    // Re-wrap to carry the entity name; the spec-level throw has none.
    throw SchemaReadException(
      entity: schemaName,
      fieldName: field.name,
      expectedType: V,
      actualValue: value,
      cause: error.cause,
    );
  }
}