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

Adding enum write mode to the libraries #19

Closed giuppo73 closed 8 years ago

giuppo73 commented 8 years ago

Hello there, I really appreciated this library. Protobuf util is still not mature at this time (generates beautified json code, and there's no way to avoid that). This library was lacking one thing that we really needed, though: encoding the enums as integers. I had a look at your library and I saw that it's capable of reading the enums back by integer encoding, but it was always outputting them as strings. This fork addresses that by adding a builder for the library that accepts the enum writing mode as a parameter.

bivas commented 8 years ago

This pull request contains too many breaking changes (package name for one; protobuf version etc.). I also tend not to allow wildcard imports (*) and this requests has a lot of them. This PR even changed the existing imports to wildcard. This feature (writing out enums with their ordinal value instead of name) should be first discussed as CR. As far as the feature itself, I tend not to use ordinal for enums as this approach will break when facing with 2 enum versions. e.g.

/**
* @version 1.0
**/
enum Foo {
   BAR, // 1 
   ZAR;  // 2
}

/**
* @version 2.0
**/
enum Foo {
   ARG, // 1
   BAR; // 2
}

Deserialize with ordinal will result in wrong values.