RascalSoftware / python-RAT

Python interface for RAT
1 stars 5 forks source link

Improves `ClassList` integration with Pydantic and adds JSON conversion for `Project`s #79

Closed alexhroom closed 1 month ago

alexhroom commented 2 months ago

This PR solves #76 by allowing Projects to be read and written from JSON via two new functions, project_to_json and project_from_json.

Changes

For example, the following are now all valid inputs to a Project:

Project(parameters=RATapi.ClassList([Parameter(name="My Parameter"])

Project(parameters=[Parameter(name="My Parameter")])

Project(parameters=[{'name': 'My Parameter'}]

In future, once Pydantic has integrated Numpy support (https://github.com/pydantic/pydantic/issues/9677), this will be good enough for us to use Pydantic's model_dump_json to save Projects in JSON format (via converting each ClassList of RATModels to a list of dictionaries, as it now knows how to get back from that). But for now: