Skip to content

Add modifier for nested type codec constructor#228

Open
hyeonjae wants to merge 5 commits into
linkedin:masterfrom
hyeonjae:master
Open

Add modifier for nested type codec constructor#228
hyeonjae wants to merge 5 commits into
linkedin:masterfrom
hyeonjae:master

Conversation

@hyeonjae

@hyeonjae hyeonjae commented Jun 9, 2021

Copy link
Copy Markdown

If the record has avro type, the codec is not recognized.

{
  "type": "record",
  "name": "Parent",                  
  "fields" : [
    {"name": "child", "type": "Child"}
  ]
}

To solve this problem, I suggest the following constructor modifier

parent := `
{
  "type": "record",
  "name": "Parent",                  
  "fields" : [
    {"name": "child", "type": "Child"}
  ]
}
`

modifier := func(st map[string]*Codec) {
	st["Child"] = childCodec
}

codec, err := NewCodec(parent, modifier)

As NewCodec function prototype is like below, doesn't hurt compatibility.

func NewCodec(schemaSpecification string, modifiers ...CodecModifier) (*Codec, error) 

@xmcqueen

xmcqueen commented Sep 29, 2021

Copy link
Copy Markdown
Contributor

@hyeonjae Can you provide a fail case so I can understand the problem a little more? I was toying with making that a variadic and adding a codec just the other day for a different purpose. It would be ideal to get a test case that fails. I'll look into this a bit more now that I see you've already provided some test cases. Thanks

@xmcqueen

xmcqueen commented Oct 6, 2021

Copy link
Copy Markdown
Contributor

I like this idea. I'll wait a bit for folks to comment.

@survivorbat

Copy link
Copy Markdown

I like this idea too :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants