Help? restapi custom serializer for specific field

https://plonerestapi.readthedocs.io/en/querysources/customization.html#dexterity-fields

Says:

For customizing a specific field instance, a named IFieldSerializer adapter can be registered. The name may either be the full dottedname of the field (plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation.exclude_from_nav) or the shortname of the field (exclude_from_nav).

I can't seem to get the named adapter to work to override this 'featured_image' field:

Removing the 'name' from the zcml works - I'm just lucky I have only one IRelationChoice in my schema.

=====

The schema for 'IStory': ( rfasite.content.content.story.py )

class IStory(model.Schema):
    # snip other fields
    featured_image = RelationChoice(
        title=_(u'Featured Image'),
       # snip stuff
    )

ZCML:

  <adapter factory=".serializer.FeaturedImageField"
           name="featured_image"
  />

(or)

  <adapter factory=".serializer.FeaturedImageField"
           name="rfasite.content.content.story.featured_image"
 />

serialize.py: - let's just catch it with a debug.

from rfasite.content.content.story import IStory

@adapter(IRelationChoice,IStory, Interface)
@implementer(IFieldSerializer)
class FeaturedImageField(DefaultFieldSerializer):

    def __call__(self):
        import pdb; pdb.set_trace()
1 Like

possible solution, specify your request with a Marker Interface ?

@adapter(IRelationChoice, IDexterityContent, IMigrationMarker)

:slight_smile: never trust docs and double-check with the source code, specially when something doesn't work.

I don't see any name passed to the getMultiAdapter call, so you shouldn't register the field serializer adapter with a name.

1 Like

I saw that same code. But wasn’t sure.

I didn’t trace to it like a good boy, but only assumed it was the code that was run.

That’s why I came here first before going to github and filling an issue.

In fact, I didn’t search open issues either.