Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dacreify committed Jun 15, 2020
1 parent 04f654f commit 33ac94d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/jackdaw/serdes/avro.clj
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,17 @@
(defrecord RecordType [^Schema schema field->schema+coercion]
SchemaCoercion
(match-clj? [_ clj-map]
(let [[_ unknown-fields _] (clojure.data/diff (set (keys field->schema+coercion))
(set (keys clj-map)))]
(and (every? (fn [[field-key [^Schema$Field field field-coercion]]]
(let [field-value (get clj-map field-key ::missing)]
(if (= field-value ::missing)
(.defaultValue field)
(match-clj? field-coercion field-value))))
field->schema+coercion)
(empty? unknown-fields))))
(if (map? clj-map)
(let [[_ unknown-fields _] (clojure.data/diff (set (keys field->schema+coercion))
(set (keys clj-map)))]
(and (every? (fn [[field-key [^Schema$Field field field-coercion]]]
(let [field-value (get clj-map field-key ::missing)]
(if (= field-value ::missing)
(.defaultValue field)
(match-clj? field-coercion field-value))))
field->schema+coercion)
(empty? unknown-fields)))
false))

(match-avro? [_ avro-record]
(cond
Expand Down
4 changes: 2 additions & 2 deletions test/jackdaw/serdes/avro_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@
enum-schema {:name "enum"
:type "enum"
:symbols ["a" "b" "c"]}
avro-schema (parse-schema ["long"
avro-schema (parse-schema [record-1-schema
"long"
"string"
enum-schema
record-1-schema
record-2-schema
record-3-schema])
schema-type (schema-type avro-schema)
Expand Down

0 comments on commit 33ac94d

Please sign in to comment.