-
Notifications
You must be signed in to change notification settings - Fork 812
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
Known Issue: proto.MarshalTextString cannot handle custom types with Bytes method #199
Comments
Oh. And this is tangentially related if a custom type implements
|
Actually, even if
|
customtype has its issues, but they are unfixable without breaking backwards compatibility in my opinion. The raw interface comes all the way from golang/protobuf |
proto.TextMarshaler.Text not checking the error also comes from golang/protobuf |
Yeah, I printf debugged my way to those conclusions. I can add some docs for customtype to let people know of this behavior if you make some (short + brief) bullet points on what to add. 😄 |
I thought I would just leave this issue open. But if I document the issue I can close it. Great idea :) |
Also, tangentially related: I just ran into this today: where database.Allowed is a struct and Any ideas before I dig through the code? |
Did you import github.com/gogo/protobuf/proto or github.com/golang/protobuf/proto? |
In my .proto file I import github.com/gogo/protobuf/proto.proto |
It seems proto.MessageType returns nil in jsonpb/jsonpb.go
|
Yep, I actually am on that line right now. :) |
Why it returns nil and other don't is a mystery to me at this point in time. |
Can you maybe tell me the underlying type of sermocrm.com/pkg/database.Allowed ? |
It doesn't implement proto.Message, so perhaps that's why? type Allowed struct {
input string
tables []string
names []string
} |
My customtypes don't either. |
Try making a struct with nullable = false. |
I meant something like
message Bar {
bytes foo = 1 [(gogoproto.customtype = "Foo"), (gogoproto.nullable = false)];
} which is essentially what I'm trying to do. |
Fair so a struct. Yes that is also the only way we will get into that if. |
Do you mean why my code is like that? |
No, my code. |
Ah, gotcha. |
I think the only thing to really to do is call MarshalJSON
|
Could you maybe try if that works for you? |
Why not just call json.Marshal on |
fair enough :) Does it the modified code work for you? |
haha, I suppose after making a handful of issues the last couple days submitting a pr is the least I could do ;) |
Well then you can at least get some credit for all the work you have done. So you can also add yourself and/or your company to the AUTHORS and/or CONTRIBUTORS as appropriate. |
This issue is related #147 |
Docs made a31fa02 |
Slight issue: if the struct doesn't return This happens b/c I have a |
Could you make a new issue for the jsonpb case please? |
yep |
If a custom type implements
proto.raw
(i.e., has aBytes() []byte
method)proto.TextMarshaler.writeStruct
will call it, causing invalid bytes to be written.For example, I have a UUID type with a
Bytes() []byte
method which returns the UUID's text format as a slice of bytes (it reduces allocations for other methods likeMarshalText
).I use this as a custom type and when I do I get the errors seen here.
I'm not sure what your take is on this. Either there should be some docs (I know you said before custom type has issues, so if I could help let me know) or instead of
Bytes() []byte
the interface should betype raw interface { bytes() []byte }
so no external types can implement it.The text was updated successfully, but these errors were encountered: