tarantool/avro-schema

validate, default value MAP convert to ARRAY

theonedemon opened this issue · 2 comments

avro_schema = require('avro_schema')
schema = {type = 'record',name = 'user', fields = {{type = 'long*', name = 'id'},{ type = {type = 'map', values = 'long'}, name = 'matching', default = {}}}}

ok, h = avro_schema.create(schema)
ok, m = avro_schema.compile(h)

ok:

m.flatten({id = 5})
---
- true
- [5, {}]

not ok:

avro_schema.validate(h, {id = 5})
---
- true
- matching: []
  id: 5

error:

ok, h_flat = avro_schema.validate(h, {id = 5})
m.unflatten(h_flat)
---
- false
- Expecting ARRAY, encountered MAP

hotfix:

ok, h_flat = avro_schema.validate(h, {id = 5})
setmetatable(h_flat.matching, { __serialize="map"})
m.flatten(h_flat)

thank @Totktonada !

Related to #18.