Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modifier for nested type codec constructor #228

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

hyeonjae
Copy link

@hyeonjae hyeonjae commented Jun 9, 2021

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
Copy link
Contributor

xmcqueen commented Sep 29, 2021

@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
Copy link
Contributor

xmcqueen commented Oct 6, 2021

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

@survivorbat
Copy link

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