Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyangbind/lib/serialise.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ def default(self, obj):
return ndict
elif isinstance(obj, (str,)):
return str(obj)
elif isinstance(obj, (int,)):
return int(obj)
elif isinstance(obj, (YANGBool, bool)):
return bool(obj)
elif isinstance(obj, (int,)):
return int(obj)
elif isinstance(obj, Decimal):
return self.yangt_decimal(obj)

Expand Down
6 changes: 6 additions & 0 deletions tests/serialise/json-serialise/json-serialise.yang
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ module json-serialise {
}
}

container c2 {
leaf-list ll0 {
type boolean;
}
}

container two {
leaf string-test {
type string;
Expand Down
8 changes: 8 additions & 0 deletions tests/serialise/json-serialise/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def test_full_serialise(self):
external_json = json.load(fp)
self.assertEqual(pybind_json, external_json, "JSON did not match expected output.")

def test_boolean_before_int_serialize(self):
self.serialise_obj.c2.ll0 = [True, False]

pybind_json = json.loads(dumps(self.serialise_obj))

self.assertIs(pybind_json["c2"]["ll0"][0], True, "JSON did not match expected output.")
self.assertIs(pybind_json["c2"]["ll0"][1], False, "JSON did not match expected output.")


if __name__ == "__main__":
unittest.main()
Loading