[plone.restapi] Serialization/deserialization of collective.z3cform.datagridfield fields?

We have a DX type using collective.z3cform.datagridfield where the values of one grid column are datetime instances.
So sending the value of such a grid field as JSON does not work out of the box because JSON does not support datetime instance. Of course I can convert datetime values to ISO8601 but how would plone.restapi deserialize this particular columns for this particular field on the Plone side?

The overall datastructure is like this:

grid_value = [
{start: some_datetime, ....},
{start: some_other_datetime, ...}
]

-aj

In plone.restapi we use DateTime to parse a ISO8601 string back to datetime: https://github.com/plone/plone.restapi/blob/master/src/plone/restapi/deserializer/dxfields.py#L89

You can add a (de)serializer that takes the json structure and get a dict out of it. I'm guessing the datagridfield will be smart enough to validate this, or you'll have to to that in the deserializer.

Adding a (de)serializer for a datagridfield should be enough to add support for it throughout plone.restapi, though you can only find out by using it :slight_smile:

Thanks for the pointer. I did not dig into the plone.restapi internals. But yes, a field specific deserializer might be part of the solution. In this case, such a deserializer must introspect the row schema of grid field and at least perform a specific deserialization for date/datetime fields within the row schema.

For now I am sending Python pickles around for this specific usecase :slight_smile:

For z3cform.datagridfield the field definition looks like

    form.widget(table=DataGridFieldFactory)
    table = schema.List(title=_(u'Seminar dates'),
                        required=False,
                        value_type=DictRow(title=_(u'Seminar date'), schema=ITableRowSchema))

So for a deserializer you would have to override the default deserializer for IList. I don't see any reasonable way to register a deserializer specific to IList and its value_type schema....hm....

Here is a related bug report.

The IFieldDeserializer adapter is too weak in my opinion and needs more context information - at least in this particular case where the IList field "shadows" the underlaying z3cform.datagridfield.

I think there are several similar problems with DictRow (trying to use Images/Blobs, relation fields etc. ).

Could it be possible to have something like
(schema) DataGridList which could be based on IList, but with more options: like the ability to choose 'deserializer' ?

Ah, thanks!
We'll have to figure out something for (de)serializing the value_type correctly.

Perhaps an optional multi-adapter lookup to (, <interface of value type)) or something similar would help...or just pass additional context information to registered adapter besides the value.