core: CircularReferenceException in custom ItemDataProvider

Hello,

I’m implementing 2 custom data providers, connecting on WordPress API: 1 for collection, 1 for item. For the first one, I can easily inject the serializer service. But for the item, I get a CircularReferenceException.

A solution would be to create an event subscriber which listens to kernel.request event and serialize the controller result, but it’s not generic at all (and I don’t find it very clean…).

A better solution would be to listen to SerializerAwareInterface on my ItemDataProvider from API Platform, and if so call setSerializer method.

What do you think of it @api-platform/core-team?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (20 by maintainers)

Most upvoted comments

I need to serialize this list to an array of AppBundle\WordPress\Post objects.

Do you mean deserializing the JSON data into the Post objects? I guess it makes sense then…

A better solution would be to listen to SerializerAwareInterface on my ItemDataProvider from API Platform, and if so call setSerializer method.

Or some other tricks like lazy services which should help…

@soyuka that’s the main idea, but we should first inject the serializer in services which call ItemDataProvider::getItem, to inject it like the serializer does: https://github.com/symfony/serializer/blob/master/Serializer.php#L60

@vincentchalamon IMO it could be done in api-platform

A data provider isn’t supposed to do serialization?