Produces uncompilable Java when a field is called "default"
GoogleCodeExporter opened this issue · comments
What steps will reproduce the problem?
1. Create Java files using java_bean for Google Cloud Print
https://developers.google.com/cloud-print/docs/cdd
2. Try to compile the Java files.
3. View errors because fields in Java are named "default" as the originals were
in the protobuf definition.
What is the expected output? What do you see instead?
I expect some change to allow these to complete. The getter and setter names
can stay the same but the field needs to be called something else. default_ or
dfault for example.
What version of the product are you using? On what operating system?
1.0.8, Java 1.8.0, Windows 7.
Original issue reported on code.google.com by matt...@jaggard.org.uk
on 19 May 2014 at 8:39
The compiler option 'underscore_on_vars' will do the trick.
See https://code.google.com/p/protostuff/wiki/CompilerOptions
Original comment by david.yu...@gmail.com
on 19 May 2014 at 2:12
Whilst that workaround makes it slightly more of an edge case, it's not
possible for me because I'm using Gson to convert the POJO into JSON. That
means that I get all of my results incorrectly. {"name":"Betsy"} becomes
{"name_":"Betsey"}
I don't mind too much that I get the wrong result for {"default_":"MyDefault"}
and I can't think of a way to fix that issue.
Original comment by matt...@jaggard.org.uk
on 20 May 2014 at 8:13
How protobuf code generator behaves in this case?
Original comment by schepano...@gmail.com
on 12 Feb 2015 at 10:15
Fixed in https://github.com/protostuff/protostuff-compiler, underscore is added to field name if it is reserved java keyword.