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

Fix GetBSON() method usage #485

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open

Fix GetBSON() method usage #485

wants to merge 1 commit into from

Conversation

bozaro
Copy link

@bozaro bozaro commented Aug 31, 2017

Original issue

You can't use type with custom GetBSON() method mixed with structure field type and structure field reference type.

For example, you can't create custom GetBSON() for Bar type:

struct Foo {
	a  Bar
	b *Bar
}

Type implementation (func (t Bar) GetBSON() ) would crash on Foo.b = nil value encoding.

Reference implementation (func (t *Bar) GetBSON() ) would not call on Foo.a value encoding.

After this change

For type implementation func (t Bar) GetBSON() would not call on Foo.b = nil value encoding.
In this case nil value would be seariazied as nil BSON value.

For reference implementation func (t *Bar) GetBSON() would call even on Foo.a value encoding.

Original issue
---

You can't use type with custom GetBSON() method mixed with structure field type and structure field reference type.

For example, you can't create custom GetBSON() for Bar type:

```
struct Foo {
	a  Bar
	b *Bar
}
```

Type implementation (`func (t Bar) GetBSON()` ) would crash on `Foo.b = nil` value encoding.

Reference implementation (`func (t *Bar) GetBSON()` ) would not call on `Foo.a` value encoding.

After this change
---

For type implementation  `func (t Bar) GetBSON()` would not call on `Foo.b = nil` value encoding.
In this case `nil` value would be seariazied as `nil` BSON value.

For reference implementation `func (t *Bar) GetBSON()` would call even on `Foo.a` value encoding.
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.

1 participant