Skip to content

to_jsonld() produces invalid JSON when multiplicity constraint violated #56

@apdavison

Description

@apdavison

Since we are permissive on object creation, serialization to JSON-LD should work even if the object gives validation failures.

However, under some circumstances, to_jsonld() produces a data structure that cannot be saved as a JSON string.

Example:

    dataset = omcore.Dataset(digital_identifier=[omcore.DOI(identifier="abc"), omcore.DOI(identifier="def")])
    # this is valid JSON-LD, but violates the openMINDS schema, which only accepts a single digital identifier
    failures = dataset.validate(ignore=["required"])
    assert len(failures) == 1
    assert failures["multiplicity"] == ['digital_identifier does not accept multiple values, but contains 2']

    data = dataset.to_jsonld()
    json.dumps(data) 

Everything works until the last line, which gives TypeError: Object of type DOI is not JSON serializable.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions