I'm new to Python Marshmallow module and quite like it for serialization and de-serialization. I know that after defining a schema, I can easily serialize a dict or an object to JSON format using schema.dumps
method.
However, I wonder how I could serialize an object or a dict to another format than JSON. For example, sometimes I'd like to serialize an object to XML.
I saw this issue in Marshmallow's Github repo. It seems its doable by playing with something called json_module
. However, I can't really follow that thread because I'm quite new to Marshmallow.
Logically, schema.dumps
seems to be the right method to do that, but from the documentation, I didn't see a possibility of serializing data to any other format than JSON.
I'd appreciate it if anyone could give me an example of converting a dict to an XML string.
Edit: Thanks for the answer using dicttoxml
. It's a good module and indeed it solves my problem. However, isn't the "output formatt control" a built-in feature of marshmallow
? I though if it were, then the support to controlling output format should be in schema.dumps
method? Or did I miss anything?