Hi,
I was attempting to test the --force-defaults option of the flatc compiler, but I can't seem to make it work as expected.
I am using version 2.0 of the compiler:
flatc --version
flatc version 2.0.0
I reproduced the issue with a simple schema:
namespace default_test;
table test_record
{
prefix:uint64;
data:uint64 = 2989;
suffix:uint64;
}
root_type test_record;
I then created a JSON data file:
{
prefix: 12302652060373662634,
suffix: 12302652060373662634,
}
I then used flatc to generate a binary serialization from this JSON file:
flatc --force-defaults -b test_record.fbs test_record_data.json
I would have expected to see the 'data' field serialized as 2989 (because of the --force-defaults option), but it is missing from the serialization (I verified with a hex viewer).
If I specifically set to a value, I can see the value serialized as expected.
Also, according to
https://google.github.io/flatbuffers/md__schemas.html:
- A field that has the value null (e.g. field: null) is intended to have the default value for that field (thus has the same effect as if that field wasn't specified at all).
But if I try to follow this instruction by setting data to null:
{
prefix: 12302652060373662634,
data: null,
suffix: 12302652060373662634,
}
flatc will complain with:
error: /home/laur/temp/test_record_data.json:6: 0: error: invalid number: "null"
Am I missing something about how --force-defaults is supposed to work or is that setting currently broken? How can I make default values work with a JSON file?
Thank you,
Laurentiu