Closed kingluo closed 1 year ago
There's no easy way. You have to either replace the LDAPDN
classes with their str
representation in the entry, or create a custom JSONEncoder
for LDAPDN
. I think the LDAPEntry
and LDAPValueList
objects should be JSON serializable, they're inherited from dict
and list
respectively.
@noirello Thanks for your help. Now I encapsulate bonsai in OpenResty Lua library: https://github.com/kingluo/lua-resty-ffi-ldap/blob/main/resty/ffi/ldap.py
If you have time, please have a look. Any suggestions are welcome! Thank you!
I think this is a shorter and maybe a little bit faster approach:
for ent in res:
item = dict(ent)
item["dn"] = str(item["dn"])
ents.append(item)
Then this here: https://github.com/kingluo/lua-resty-ffi-ldap/blob/4f0f625e69dba2d676787641db29b6918b2d778f/resty/ffi/ldap.py#L111-L118
Other then that, I have no notes. That's a very compelling language mix, you've got there. 😃
@noirello It's more pythonic! Thanks for your suggestion!
@noirello For example, how to convert such a search result into a JSON array/object without constructing a new list/dict and copying fields one by one?
LDAPEntry
andLDAPDN
is not JSON serializable.