Any way to stop rename field in codegen?

631 views
Skip to first unread message

ke ren

unread,
Mar 8, 2018, 6:41:28 AM3/8/18
to Protocol Buffers
Hi,

I am trying to migrate our project to protobuf and find one annoying feature in protobuf c# codegen. It will automatically rename the field name defined in proto during codgen to fit camel convention. For example, NURBSSurface will be renamed to Nurbssurface, XRay to Xray etc. It causes big naming changes in code and back compatibility issue with old data format which is field name case senstitive. Is there any way to stop codegen renaming?

Thanks,

Ke

Jon Skeet

unread,
Mar 8, 2018, 8:24:20 AM3/8/18
to Protocol Buffers
On Thursday, 8 March 2018 11:41:28 UTC, ke ren wrote:
I am trying to migrate our project to protobuf and find one annoying feature in protobuf c# codegen. It will automatically rename the field name defined in proto during codgen to fit camel convention. For example, NURBSSurface will be renamed to Nurbssurface, XRay to Xray etc. It causes big naming changes in code and back compatibility issue with old data format which is field name case senstitive. Is there any way to stop codegen renaming?

No, that's not configurable. (It was in my original proto2 port, but we reduced the set of options for the proto3 version for simplicity.)

For some cases, just changing the protobuf field name  would work, e.g. x_ray will create a property called XRay. You probably don't want a field called n_u_r_b_s_surface though...

Jon

ke ren

unread,
Mar 8, 2018, 8:51:45 AM3/8/18
to Protocol Buffers
Hi Jon,

Thanks to confirm it. will JsonParser use pbr::OriginalName or the field name in generated class for json deseriliazation? If it uses the field name, probably it would work. Otherwise, probably have to consider data deser bridge or something.

Ke

Jon Skeet

unread,
Mar 9, 2018, 8:46:41 AM3/9/18
to Protocol Buffers
On Thursday, 8 March 2018 13:51:45 UTC, ke ren wrote:
Thanks to confirm it. will JsonParser use pbr::OriginalName or the field name in generated class for json deseriliazation? If it uses the field name, probably it would work. Otherwise, probably have to consider data deser bridge or something.

The JSON parser will use the json_name part from the descriptor:

That can be set on a per-field basis with the json_name option, so that may help you.

Jon

 

ke ren

unread,
Mar 10, 2018, 9:01:47 AM3/10/18
to Jon Skeet, Protocol Buffers
Thanks! very helpful

--
You received this message because you are subscribed to a topic in the Google Groups "Protocol Buffers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/protobuf/HeTwIRb7DCs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to protobuf+unsubscribe@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages