diff --git a/lib/avro/datum.php b/lib/avro/datum.php index 1a17a06..f6dbd69 100644 --- a/lib/avro/datum.php +++ b/lib/avro/datum.php @@ -76,7 +76,7 @@ class AvroIODatumWriter * Schema used by this instance to write Avro data. * @var AvroSchema */ - private $writers_schema; + public $writers_schema; /** * @param AvroSchema $writers_schema diff --git a/lib/avro/schema.php b/lib/avro/schema.php index a8853d4..9401e11 100644 --- a/lib/avro/schema.php +++ b/lib/avro/schema.php @@ -459,9 +459,11 @@ public static function is_valid_datum($expected_schema, $datum) case self::REQUEST_SCHEMA: if (is_array($datum)) { - foreach ($expected_schema->fields() as $field) - if (!array_key_exists($field->name(), $datum) || !self::is_valid_datum($field->type(), $datum[$field->name()])) - return false; + foreach ($expected_schema->fields() as $field) { + $value = isset($datum[$field->name()]) ? $datum[$field->name()] : $field->default_value(); + if (!self::is_valid_datum($field->type(), $value)) + return false; + } return true; } return false;