anydoby / protobuf-java-format

Automatically exported from code.google.com/p/protobuf-java-format
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Serializing a builder that has a default value, but doesn't override it, creates json without that value. #44

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. define message with a field with default value.
2. populate a builder of that message, but don't set that field.
3. observe that json doesn't contain default value.

What is the expected output? What do you see instead?
should contain that field, but with default value set.

What version of the product are you using? On what operating system?
version 1.2, on a mac.

Please provide any additional information below.

Original issue reported on code.google.com by storsv...@telenordigital.com on 25 Oct 2012 at 2:57

GoogleCodeExporter commented 9 years ago
This code sets all fields with default value set, to the default value: Maybe 
you could loop on this instead of getFields() on the Message, because that 
doesn't return unset field, not even fields with default value set:

        for(Descriptors.FieldDescriptor desc : builder.getDescriptorForType().getFields()) {
            if(desc.hasDefaultValue()) {
                builder.setField(desc, desc.getDefaultValue());
            }
        }

Original comment by storsv...@telenordigital.com on 25 Oct 2012 at 9:18