Fix serialization of JSON-LD subarrays
Properties like "tag" could be lists containing multiple subclasses of ActivityObject. Make sure to serialize them recursively instead of outputting them as they are, because otherwise we could get a bunch of nulls in the resulting JSON and that wouldn't necessarily be a valid JSON-LD object. Fix: #2451
This commit is contained in:
parent
8ec984c3ff
commit
cdc833657f
2 changed files with 25 additions and 18 deletions
|
@ -194,6 +194,11 @@ class ActivityObject:
|
|||
try:
|
||||
if issubclass(type(v), ActivityObject):
|
||||
data[k] = v.serialize()
|
||||
elif isinstance(v, list):
|
||||
data[k] = [
|
||||
e.serialize() if issubclass(type(e), ActivityObject) else e
|
||||
for e in v
|
||||
]
|
||||
except TypeError:
|
||||
pass
|
||||
data = {k: v for (k, v) in data.items() if v is not None and k not in omit}
|
||||
|
@ -306,7 +311,9 @@ class Link(ActivityObject):
|
|||
|
||||
def serialize(self, **kwargs):
|
||||
"""remove fields"""
|
||||
omit = ("id", "type", "@context")
|
||||
omit = ("id", "@context")
|
||||
if self.type == "Link":
|
||||
omit += ("type",)
|
||||
return super().serialize(omit=omit)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue