Closed cmdoret closed 1 year ago
I found the fix, the fields.Nested
with many=True
seems to do that, it was just not documented.
class OrganizationSchema(JsonLDSchema):
_id = fields.Id()
name = fields.String(schema.name)
members = fields.Nested(schema.member, PersonSchema, many=True)
class Meta:
rdf_type = schema.Organization
model = Organization
output:
{
"http://schema.org/member": [
{
"http://schema.org/givenName": "John",
"@id": "X",
"@type": [
"http://schema.org/Person"
]
},
{
"http://schema.org/givenName": "Max",
"@id": "Y",
"@type": [
"http://schema.org/Person"
]
}
],
"http://schema.org/name": "SomeOrg",
"@id": "SO",
"@type": [
"http://schema.org/Organization"
]
}
Hello !
I am trying to serialize a list of nested fields with calamus. In the example below, I use an organization which has (a list of) 2 members.
The code runs if the members are of type
field.String
, but when I make them aPerson
, it fails with:Traceback:
``` Traceback (most recent call last): File "marshmallow/fields.py", line 757, in __init__ self.inner = resolve_field_instance(cls_or_instance) File "marshmallow/utils.py", line 352, in resolve_field_instance raise FieldInstanceResolutionError marshmallow.exceptions.FieldInstanceResolutionError The above exception was the direct cause of the following exception: Traceback (most recent call last): File "nested.py", line 35, inI would have expected the following output instead:
Is there currently a recommended way to do this with calamus ?
Env: python 3.10.6, calamus 0.4.1