Skip to content

Serialize nested object by id only #55

@Panaetius

Description

@Panaetius

Currently when serializing with fields.Nested, we always serialize the whole object and add @type information.

In some cases, we want to instead serialize an @id reference instead of the whole nested object.

Theoretically this would be possible with something like fields.Nested(schema.address, AddressSchema, only=("_id",)), but that will result in something like {"@id": "...", "@type": "..."}, whereas for an id reference we wouldn't want to have the @type information included.

We could add an addition flag to fields.Nested to skip adding the @type but that's probably not a clean solution.

A new field like fields.IdReference(schema.address, AddressSchema) would make sense that still takes the child schema like fields.Nested but only returns the @id of the child. On deserializing, it should look up the @id to see if it can get that object in the data and if not, raise an exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions