Open nicola-lunghi opened 4 years ago
That's the way to do it right now. I believe the only nonserializable type is the Variant. I would like to put a function that turns the result into a plain object because I think that's a common use case. I have implemented this in the test suite somewhere. I can probably just put that into the library.
FWIW, json.dumps
takes cls
argument, allowing usage of a custom encoder. Maybe it's worth including such an encoder in the library.
Something similar to this?
import json
from dbus_next import Variant
class DBusEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Variant):
return obj.value
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(self, obj)
json.dumps(data, cls=DBusEncoder)
It would be nice to have this in the dbus-next library.
Hi,
I need to encode the result of a dbus message with json. How can I make the dbus object type serializable? for now I am doing (from your example client)
There's a better way to get a serializable body without all the dbus types?
Thanks Nick