-
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
defining a customtype as a fake proto message causes problems with jsonpb, prototext and possibly some others #132
Comments
This issue is even harder: nor protobuf-text, nor jsonpb checks for implementation of TextMarshaler/json.Marshaler for fields of a message. So tests can pass for custom type, but not for messages with fields with that type. |
I don't see you actually using the customtype extension in types.proto
Or am I missing something? |
No, it should not. Generated Go code will actually contain Native type references, and the type itself is already implemented in a separate file (code block at the beginning). This works because code generation bypasses all checks for Native message type because it is present in the import (you suggested this technique, by the way :) ). |
I don't think so. Please link my previous suggestion. |
#126 |
Ah yes context is very helpful thank you :) |
So why can't you export the fields? |
Because the type of the field is unknown to protobuf (interface{}). Custom marshaling/unmarshaling procedures allows us to preserve comparability guaranties for that field. This can't be achieved in any other way that is known to me. |
Yeah and if you want to create any custom type you don't intend to always have struct types. |
Yes. Basically, we're actually not using jsonpb right now, but I thought that you should be aware of the problem. |
So basically someone would need to fully explore this and make this a proper feature and not just a hack. |
This happens with any unexported field. E.g., if I use this
The test "TestFooProtoText" panics with
|
No you can't declare private customnames sorry. |
All good, thank you 🙂
|
Is this fixed by #239 ? |
Can be reproduced with custom type:
Auto-generated tests for serialization will fail with panic:
Jsonpb definitely has no code to test for unexported fields.
But this can be fixed easier: jsonpb code should check if object implements json.Marshaler.
The text was updated successfully, but these errors were encountered: