bivas / protobuf-java-format

Provide serialization and de-serialization of different formats based on Google’s protobuf Message. Enables overriding the default (byte array) output to text based formats such as XML, JSON and HTML.
BSD 3-Clause "New" or "Revised" License
153 stars 97 forks source link

Serialize enum with number by default #39

Closed mchataigner closed 4 months ago

mchataigner commented 7 years ago

In order to reduce the size of json payload, it should be better to send only the enum number instead of the value name.

melloware commented 7 years ago

I like the idea. Unfortunately it doesn't look like there has been much activity from the committers on this project lately which is a shame because it is an extremely useful library!

scr commented 7 years ago

Is it possible to alter/choose the behavior? I appreciate the feature, but would much prefer making what is desired possible rather than changing the default.

Also, can you add a test for this (that both formats are read properly)?

bivas commented 7 years ago

Actually, it's a matter of compatibility. Enums have both name and order - You can easily break the compatibility by rearranging the order of the enums in your message, while if using name, it is somewhat easier to locate API breakage.

I would go with @scr offer to add a behavior switch and leave the current (by name) behavior as the default one.