batou
batou copied to clipboard
Object of type NetLoc is not JSON serializable
Having this code:
import batou.utils
import batou.componet
import batou.lib.file
class MyComponent(batou.component.Component):
def configure(self):
self.address = batou.utils.Address(self.host.fqdn, 1234)
self += batou.lib.file.JSONContent(
'my.json',
data={
"myAddress": self.haproxy.address.connect
})
Leads to an
ERROR: TypeError('Object of type NetLoc is not JSON serializable')
To solve this, an explicit converting to a string did work -- but unsure whether we should default to some str representation here as we have e.g. for Jinja-templating.
We can do this by implementing a custom json encoder in JSONContent.
Note that deserialization will likely not be possible in a roundtrip style.
I can see the same issue with YAMLContent