Trying to deserialize DataGridField using block transformer for Plone Restapi

Good morning, Plone Community!

I am in the process of getting existing DataGridFields to work in Volto without having to create a migration script using the block transformer code found in Plone Restapi documentation. The code i was using is found below:

# -*- coding: utf-8 -*-
from collective.z3cform.datagridfield.datagridfield import DataGridFieldFactory
from collective.z3cform.datagridfield.row import DictRow
from plone.schema.jsonfield import JSONField
import json
from Products.validation import V_REQUIRED
from plone.restapi.interfaces import IBlockSearchableText
from zope.component import adapter
from plone.restapi.behaviors import IBlocks
from zope.publisher.interfaces.browser import IBrowserRequest


MIXEDFIELD_SCHEMA = json.dumps(
    {
        'type': 'object',
        'properties': {'items': {'type': 'array', 'items': {'type': 'object', 'properties': {}}}},
    }
)

from plone.autoform import directives
from plone.dexterity.content import Container
from plone.namedfile.field import NamedBlobFile
from plone.schema.email import Email
from plone.supermodel import model
from yc.graduateapplication import _
from z3c.form.browser.radio import RadioFieldWidget
from zope import schema
from zope.interface import Interface
from zope.interface import implementer
from plone import api
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary
from zope.interface import provider
from zope.schema.interfaces import IContextAwareDefaultFactory



class IEmployerAddress(Interface):
    employer = schema.TextLine(
        title=_('Employer Name'),
        required=False,
        readonly=False,
    )

    employerPhone = schema.TextLine(
        title=_('Employer Phone'),
        required=False,
        readonly=False,
    )
    street = schema.TextLine(
        title=_("Street"),
        required=True,
        readonly=False,
    )

    city = schema.TextLine(
        title=_("City"),
        required=True,
        readonly=False,
    )
    state = schema.TextLine(
        title=_("State"),
        required=True,
        readonly=False,
    )

    zip = schema.TextLine(
        title=_('Postal Code'),
        required=True,
        readonly=False,
    )


class IRecommendation(Interface):
    name = schema.TextLine(
        title=_('Name'),
        description=_('Recommender'),
        required=True,
        readonly=False,
    )

    email = schema.TextLine(
        title=_('Email'),
        required=True,
        readonly=False,
    )

    ioc = schema.TextLine(
        title=_('Institution/Organization/Company'),
        required=True,
        readonly=False,
    )

    address = schema.TextLine(
        title=_('Address'),
        required=True,
        readonly=False,
    )

    phoneNumber = schema.TextLine(
        title=_('Telephone Number'),
        required=True,
        readonly=False,
    )

    relationship = schema.TextLine(
        title=_('Relationship to You'),
        required=True,
        readonly=False,

    )


class IApplicationForm(model.Schema):
    """ Marker interface for Admissions
    """

    directives.write_permission(employerAddress='yc.graduateapplication.AddApplicationForm')
    employerAddress = JSONField(
        title=_("Employer's Information"),
        description=_('Name Phone Street City State Zip'),
        widget='employer_widget',
        schema=MIXEDFIELD_SCHEMA,
        required=False,
        readonly=False,
        default={'items': []},
        missing_value={'items': []},
    )
    directives.write_permission(references='yc.graduateapplication.AddApplicationForm')
    directives.widget(references=DataGridFieldFactory)
    references = schema.List(
        title=_('Please list three references who can speak highly on your behalf.'),
        description=_('Under the Family Educational Right to Privacy Act of 1974 (FERPA) (20 U.S.C. 1232g; 34 CFR '
                      'Part 99) which gives students the right to inspect and review their educational records, '
                      'students may waive their right to see specific confidential statements and letters of '
                      'recommendations. In the belief that applicants, and the person from whom they request '
                      'recommendations, may wish to preserve the confidentiality of those recommendations,'),
        # required=True,
        required=False,
        value_type=DictRow(title=u'Table', schema=IRecommendation),
        default=[{'name': '', 'email': '', 'ioc': '', 'address': '', 'phoneNumber': '', 'relationship': ''},
                 {'name': '', 'email': '', 'ioc': '', 'address': '', 'phoneNumber': '', 'relationship': ''},
                 {'name': '', 'email': '', 'ioc': '', 'address': '', 'phoneNumber': '', 'relationship': ''}],
    )


@implementer(IApplicationForm, IBlockSearchableText)
@adapter(IBlocks, IBrowserRequest)
class ApplicationForm(Container):
    """
    """

    def __init__(self, context, request):
        self.context = context
        self.request = request

    def __call__(self, block_value):
        return block_value['applicationform']

Unfortunately, I get the following error when I go to save this in Volto:

2022-10-08 08:32:11,243 ERROR   [Zope.SiteErrorLog:252][waitress-0] 1665232331.2430110.7426793945138253 http://localhost:3000/grad/POST_application_json_
Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 162, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 371, in publish_module
  Module ZPublisher.WSGIPublisher, line 274, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 63, in call_object
  Module plone.rest.service, line 22, in __call__
  Module plone.restapi.services, line 19, in render
  Module plone.restapi.services.content.add, line 55, in reply
  Module plone.restapi.services.content.utils, line 63, in create
  Module plone.dexterity.factory, line 44, in __call__
ValueError: Error whilst constructing content for applicationform using class yc.graduateapplication.content.applicationform.ApplicationForm: __init__() got an unexpected keyword argument 'title'

What should be done to ensure that datagridfields work in Volto without having to write a migration script because we have a number of content already that will not be able to display if in the event we switch to Volto? Specifically, how can I get the deserializer transformers to work as intended in Volto?

I thank you kindly.

Sincerely,

rbrown12

I was able to resolve the issue without using this method. I modified how the widgets are displayed for this particular field in Volto frontend and it works just fine! No longer a need to deserialize this.