Jsonpb support
It would be great to support jsonpb. Standard library's json package has an issue to work with protobuf.
Hello, I really don't understand what you want from Iris, protos are not the same as JSON, we can't do Marshal/Unmarshal on-fly of any object. You can do it by-hand by your own, iris has nothing to do with this matter. There is already proto cli plugin which will generate masrhal/unmarshal functions for each of your proto payloads.
Could you please explain us better what exactly is that you want?
Thanks, Gerasimos Maropoulos
Sorry for not explaining it clearly.
I use iris as an gateway to grpc microservices. Sending grpc response to client by ctx,JSON() will cause wrong json field name issue. It would be great to have a ctx.JSONPB() which invoke jsonpb marshaler to generate JSON instead of standard json library.
Ofc, send us a link of a jsonpb marshaler lib that you tested and we can use which is not a CLI app/generator and we can add a function like this on the Context. In short, how are you doing this so far without a ctx.JSONP func?
Here is the jsonpb lib and sample code.
func SendJsonPB(ctx iris.Context, p proto.Message) {
j := &jsonpb.Marshaler{}
r, _ := j.MarshalToString(p)
ctx.ContentType(context.ContentJSONHeaderValue)
ctx.WriteString(r)
}
@siehc i think its better to have it break it part and just making the separate repo to work with iris.context. Post the repo link to here as others can see that there is an app to work with iris. @kataras is that possible? the code base is too big for now, i think we should split it up to have other repo to work directly with iris.Context. i think the Context is pretty stable and robust now.
Or, just make json marshaller in context.JSON() configurable?
@siehc the context.JSON as all of the context methods can be overriden by custom implementations, take a look at the _examples/routing/custom-context.
@jjhesk The jsonpb library is huge because it depends on the github.com/golang/protobuf library itself... so you know why we can't add this, the avg time to download and install Iris will probably took x4 time than it currently does, I am sorry we can't add everything, this is why Iris is so modular, so you can add your own things if you want so like the SendJsonPB method you wrote above.
Thanks.
@siehc just letting you know about the new context methods for protos:
Context.Protobuf(proto.Message)sends protobuf to the clientContext.JSONis able to send protos as JSON as wellContext.ReadProtobuf(ptr)binds request body to a proto messageContext.ReadJSONProtobuf(ptr, ...options)binds JSON request body to a proto message