-
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
jsonpb: unmarshalling of custom []byte type #220
Comments
Do you have an UnmarshalJSON method for your customtype |
I think later this code was added
To check for a customtype with an underlying []byte type |
Here is this Raw type - so yes, it has UnmarshalJSON method and its called. Btw looks like MarshalJSON never called as default info encoded as base64 after |
This line is called when marshalling |
Have you tried removing the pointer from Raw for the MarshalJSON method? |
So basically you will have
|
Yep, I tried this before - and tests were failing.. But what I tried now is removing pointer as you suggested and also changed marshaling to: // Default handling defers to the encoding/json library.
var b []byte
var err error
if m, ok := v.Interface().(json.Marshaler); ok {
b, err = m.MarshalJSON()
} else {
b, err = json.Marshal(v.Interface())
}
if err != nil {
return err
}
/*
b, err := json.Marshal(v.Interface())
if err != nil {
return err
}
*/ And now tests pass... |
update: sorry, looks like I did a mistake, removing pointer is enough, I will check again)) Give me some time |
Ok great. So is removing the pointer an option for you, i.o.w. can we close the issue? |
Yes, sorry for disturbing... Removing pointer is enough, looks like when I tried to do this before I also broke something in another place attempting to find solution. Actually when I did this type I saw that uuid example had no pointer in Thanks! |
I have to say that this solution is not ideal and causes confusion, but it is what we have. Have you tried using casttype instead of customtype? It might be possible for you to delete quite a bit of code. |
No, even have not known about it before this moment, thanks - will try to play with it. |
I think it works better than customtype. |
Hi, just tried to use
where
There is a generated function
Looks like some addition type casting needed here
|
This should fix the issue |
Hi, I just came across an issue with custom type. I saw current custom type issues but I have not understood is my case different or not.
I have custom
Raw
type that behaves the same way asjson.RawMessage
, so it's a new type derived from[]byte
.My struct that uses this type looks like:
I just updated
gogoprotobuf
library (previously I used proto2, now moving to proto3) and my autogenerated tests start failing.Raw
message encoded as base64 sojsondata
looks like:But after unmarshalling from string equality test fails because
DefaultInfo
not unmarshalled from that base64 string to[]byte
.As far as I understand my tests were passing previously because
jsonpb
did not even try to encode bytes before cd72cb9, right?Is this issue related to #201 ?
The text was updated successfully, but these errors were encountered: