HI,
i am playing with proto. and created following message -
message Generic {
Value val =1;
}
// The JSON representation for `Value` is JSON value.
message Value {
oneof value {
string StringVal = 1;
int64 IntVal = 2;
float Floatval = 3;
}
}
I would like to know how this will be represented in json. will be it like
1. {
"val": 1
}
or
{
"val" : "100"
}
2. {"val":{"IntVal":"10"}}
i am using following code to test my protobuff json representation and it
is generating - {"val":{"IntVal":"10"}}
g := v1.Generic{
Val: &v1.Value{
Value: &v1.Value_IntVal{IntVal: 10},
},
}
jsonReq = toJSON(&g)
fmt.Println("json request is: ", jsonReq) // json request is:
{"val":{"IntVal":"10"}}
func toJSON(pb proto.Message) string {
marshaler := jsonpb.Marshaler{}
out, err := marshaler.MarshalToString(pb)
if err != nil {
fmt.Println("failed to marshal:", err)
return ""
}
return out
}
i am looking for {"val" : 1} or {"val": "10"}. Can you help me in using
correct way to initialise v1.Generic ? thanks.
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
To view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/05c7840d-e447-4ae0-bedd-429c2ca946b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.