SwissDataScienceCenter / calamus

A JSON-LD Serialization Libary for Python
Apache License 2.0
29 stars 12 forks source link

Support marshmallow hooks and additional attributes in annotations. #74

Closed Panaetius closed 2 years ago

Panaetius commented 2 years ago

Currently, marshmallow settings like unknown = INCLUDE are ignored when set in the Meta of a class using JsonLDAnnotation.

Additionally, there is no way to set hooks like @pre_load for classes using JsonLDAnnotation.

We should add support for both, so the following should work:

class User(metaclass=JsonLDAnnotation):

    _id = fields.Id()
    name = fields.String(schema.name)

    class Meta:
        rdf_type = schema.User
        unknown = INCLUDE

        @pre_load
        def _preload(self, in_data, **kwargs):
            # modify in_data
            return in_data