Describe the bug
On current main (aaad20d), writing a root JSON value of false, zero, an empty string or an empty list produces {} instead of that value. This also affects RequestInformation.set_content_from_scalar, so a generated client can send a different JSON type and value than the caller supplied.
Reproduction
from kiota_serialization_json.json_serialization_writer import JsonSerializationWriter
for value in [False, 0, 0.0, "", []]:
writer = JsonSerializationWriter()
writer.write_any_value(None, value)
print(repr(value), writer.get_serialized_content())
All five outputs are b'{}'. Expected outputs are b'false', b'0', b'0.0', b'""' and b'[]', respectively.
get_serialized_content() checks the truthiness of self.value instead of whether a root value has been set. The same check also lets a falsy root value bypass the existing rejection of mixed root values and named properties.
Tested with Python 3.12 on Windows using the local JSON and abstractions packages. A two-condition fix and regression tests are prepared. This is separate from #741: that concerns empty property names, whereas this occurs with key=None and affects root values. Investigation and tests are AI-assisted.
Describe the bug
On current main (aaad20d), writing a root JSON value of false, zero, an empty string or an empty list produces
{}instead of that value. This also affectsRequestInformation.set_content_from_scalar, so a generated client can send a different JSON type and value than the caller supplied.Reproduction
All five outputs are
b'{}'. Expected outputs areb'false',b'0',b'0.0',b'""'andb'[]', respectively.get_serialized_content()checks the truthiness ofself.valueinstead of whether a root value has been set. The same check also lets a falsy root value bypass the existing rejection of mixed root values and named properties.Tested with Python 3.12 on Windows using the local JSON and abstractions packages. A two-condition fix and regression tests are prepared. This is separate from #741: that concerns empty property names, whereas this occurs with
key=Noneand affects root values. Investigation and tests are AI-assisted.