
I am currently working on trying to port the Bokeh library to Rust and came across a few quirks when serializing certain fields types specially when they have a default value set
Take this model for example:
class TestModel(Model):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
some_list = Seq(Int, default=[])
some_dict = Dict(Int, Int, default={})
obj = TestModel()
obj.some_list = []
obj.some_dict = {}
s = Serializer()
encoded = s.encode(obj)
print(serialize_json(encoded, indent=2, pretty=True))
When I try to get the JSON representation of this model using a serializer I get the following output:
{
"type": "object",
"name": "TestModel",
"id": "p1001",
"attributes": {
"some_list": []
}
}
Why is some_list present in the json while some_dict is not? Both some_list and some_dict have the same value as their defaults but for some reason the list present in the JSON but not the dict.
Another quirk I found is the way floating values are serialized in JSON. For example -1 is serialized “-1” but “-1.0” is serialized as “-1.0”. In rust, all floating values are serialized with a decimal point so its not possible to have a floating value serialized as “-1”. In the grand scheme of things, this is probably not an issue but I wanted to know if it is intended behavior or not.
On another note, thank you for building the comprehensive type system within the python library. It was a bit tricky to understand at first but it has been a huge help for me when I am writing the port in rust. A lot of the models in python could be ported to rust without much modification

