Skip to content

Exception during normalization of embedded entities where not all are ApiResources #1222

Closed
@backbone87

Description

@backbone87

I have a problem with normalization.

Datamodel: Fall (Case) <- 1:n -> Tag <- n:1 -> Tagdefinition

All 3 models are doctrine entities, but only Fall and Tagdefinition are ApiResources. Tags should be serialized within the Fall output, something like this:

{
  "@context": "/contexts/Fall",
  "@id": "/faelle",
  "@type": "hydra:Collection",
  "hydra:member": [
    {
      "@id": "/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1",
      "@type": "Fall",
      "id": "691bcf98-5c41-11e7-b7d5-046d49573cb1",
      "tags": [
        {
          "erstellungsdatum": "2017-06-30T15:09:47+00:00",
          "beschriftung": "Test"
        }
      ]
    }
  ],
  "hydra:totalItems": 1
}

This works fine up until now. I have a getTags on the Fall entity and the beschriftung (label) and erstellungsdatum (created date) are within the normalization group and get printed. however i dont know which tag it is. i want to serialize the Tagdefinition too (IRI and/or embedded within each tag). if i add the serialization group to the foreignkey "tagdefinition" in the Tag entity, i get the following error:

ApiPlatform\Core\Exception\InvalidArgumentException:
No resource class found for object of type "App\Entity\Tagdefinition".

  at vendor/api-platform/core/src/Api/ResourceClassResolver.php:58
  at ApiPlatform\Core\Api\ResourceClassResolver->getResourceClass(object(Tagdefinition), 'App\\Entity\\Fall', true)
     (vendor/api-platform/core/src/JsonLd/Serializer/ItemNormalizer.php:65)
  at ApiPlatform\Core\JsonLd\Serializer\ItemNormalizer->normalize(object(Tagdefinition), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true, 'iri' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1', 'api_normalize' => true, 'cache_key' => '7b899eea53ad666095cf9ad460b4ba97', 'circular_reference_limit' => array('00000000762694b10000000031e3a665' => 1, '000000007626940c0000000031e3a665' => 1)))
     (vendor/symfony/symfony/src/Symfony/Component/Serializer/Serializer.php:142)
  at Symfony\Component\Serializer\Serializer->normalize(object(Tagdefinition), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true, 'iri' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1', 'api_normalize' => true, 'cache_key' => '7b899eea53ad666095cf9ad460b4ba97', 'circular_reference_limit' => array('00000000762694b10000000031e3a665' => 1, '000000007626940c0000000031e3a665' => 1)))
     (vendor/symfony/symfony/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php:99)
  at Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->normalize(object(Tag), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true, 'iri' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1', 'api_normalize' => true, 'cache_key' => '7b899eea53ad666095cf9ad460b4ba97', 'circular_reference_limit' => array('00000000762694b10000000031e3a665' => 1, '000000007626940c0000000031e3a665' => 1)))
     (vendor/symfony/symfony/src/Symfony/Component/Serializer/Serializer.php:142)
  at Symfony\Component\Serializer\Serializer->normalize(object(Tag), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true, 'iri' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1', 'api_normalize' => true, 'cache_key' => '7b899eea53ad666095cf9ad460b4ba97', 'circular_reference_limit' => array('00000000762694b10000000031e3a665' => 1)))
     (vendor/api-platform/core/src/Hydra/Serializer/CollectionNormalizer.php:68)
  at ApiPlatform\Core\Hydra\Serializer\CollectionNormalizer->normalize(array(object(Tag)), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true, 'iri' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1', 'api_normalize' => true, 'cache_key' => '7b899eea53ad666095cf9ad460b4ba97', 'circular_reference_limit' => array('00000000762694b10000000031e3a665' => 1)))
     (vendor/api-platform/core/src/Hydra/Serializer/PartialCollectionViewNormalizer.php:48)
  at ApiPlatform\Core\Hydra\Serializer\PartialCollectionViewNormalizer->normalize(array(object(Tag)), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true, 'iri' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1', 'api_normalize' => true, 'cache_key' => '7b899eea53ad666095cf9ad460b4ba97', 'circular_reference_limit' => array('00000000762694b10000000031e3a665' => 1)))
     (vendor/api-platform/core/src/Hydra/Serializer/CollectionFiltersNormalizer.php:65)
  at ApiPlatform\Core\Hydra\Serializer\CollectionFiltersNormalizer->normalize(array(object(Tag)), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true, 'iri' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1', 'api_normalize' => true, 'cache_key' => '7b899eea53ad666095cf9ad460b4ba97', 'circular_reference_limit' => array('00000000762694b10000000031e3a665' => 1)))
     (vendor/symfony/symfony/src/Symfony/Component/Serializer/Serializer.php:142)
  at Symfony\Component\Serializer\Serializer->normalize(array(object(Tag)), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true, 'iri' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1', 'api_normalize' => true, 'cache_key' => '7b899eea53ad666095cf9ad460b4ba97', 'circular_reference_limit' => array('00000000762694b10000000031e3a665' => 1)))
     (vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php:420)
  at ApiPlatform\Core\Serializer\AbstractItemNormalizer->getAttributeValue(object(Fall), 'tags', 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true, 'iri' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1', 'api_normalize' => true, 'cache_key' => '7b899eea53ad666095cf9ad460b4ba97', 'circular_reference_limit' => array('00000000762694b10000000031e3a665' => 1)))
     (vendor/symfony/symfony/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php:81)
  at Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer->normalize(object(Fall), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true, 'iri' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1', 'api_normalize' => true, 'cache_key' => '7b899eea53ad666095cf9ad460b4ba97', 'circular_reference_limit' => array('00000000762694b10000000031e3a665' => 1)))
     (vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php:94)
  at ApiPlatform\Core\Serializer\AbstractItemNormalizer->normalize(object(Fall), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true, 'iri' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1', 'api_normalize' => true))
     (vendor/api-platform/core/src/JsonLd/Serializer/ItemNormalizer.php:73)
  at ApiPlatform\Core\JsonLd\Serializer\ItemNormalizer->normalize(object(Fall), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true, 'iri' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'))
     (vendor/symfony/symfony/src/Symfony/Component/Serializer/Serializer.php:142)
  at Symfony\Component\Serializer\Serializer->normalize(object(Fall), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true))
     (vendor/api-platform/core/src/Hydra/Serializer/CollectionNormalizer.php:88)
  at ApiPlatform\Core\Hydra\Serializer\CollectionNormalizer->normalize(object(Paginator), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1'), 'jsonld_has_context' => true, 'api_sub_level' => true))
     (vendor/api-platform/core/src/Hydra/Serializer/PartialCollectionViewNormalizer.php:48)
  at ApiPlatform\Core\Hydra\Serializer\PartialCollectionViewNormalizer->normalize(object(Paginator), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1')))
     (vendor/api-platform/core/src/Hydra/Serializer/CollectionFiltersNormalizer.php:65)
  at ApiPlatform\Core\Hydra\Serializer\CollectionFiltersNormalizer->normalize(object(Paginator), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1')))
     (vendor/symfony/symfony/src/Symfony/Component/Serializer/Serializer.php:142)
  at Symfony\Component\Serializer\Serializer->normalize(object(Paginator), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1')))
     (vendor/symfony/symfony/src/Symfony/Component/Serializer/Serializer.php:115)
  at Symfony\Component\Serializer\Serializer->serialize(object(Paginator), 'jsonld', array('groups' => array('fall_collection_output'), 'collection_operation_name' => 'get', 'operation_type' => 'collection', 'resource_class' => 'App\\Entity\\Fall', 'request_uri' => '/faelle', 'resources' => array('/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1' => '/faelle/691bcf98-5c41-11e7-b7d5-046d49573cb1')))
     (vendor/api-platform/core/src/EventListener/SerializeListener.php:65)
  at ApiPlatform\Core\EventListener\SerializeListener->onKernelView(object(GetResponseForControllerResultEvent), 'kernel.view', object(TraceableEventDispatcher))
  at call_user_func(array(object(SerializeListener), 'onKernelView'), object(GetResponseForControllerResultEvent), 'kernel.view', object(TraceableEventDispatcher))
     (vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php:106)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(GetResponseForControllerResultEvent), 'kernel.view', object(ContainerAwareEventDispatcher))
  at call_user_func(object(WrappedListener), object(GetResponseForControllerResultEvent), 'kernel.view', object(ContainerAwareEventDispatcher))
     (vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:212)
  at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.view', object(GetResponseForControllerResultEvent))
     (vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:44)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('kernel.view', object(GetResponseForControllerResultEvent))
     (vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php:146)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch('kernel.view', object(GetResponseForControllerResultEvent))
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:158)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:68)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:171)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (src/Resources/bin/app.php:21)

it happens on both jsonld and json normalizers.

basically this check "fails" https://github.com/api-platform/core/blob/master/src/Api/ResourceClassResolver.php#L53 but i dont even know why the check is there (especially the first "strict" part)

in terms of jsonld Fall::tags are a container of blank nodes (Tag) that contain a label, a created date and a reference to the Tagdefinition (maybe more in the future).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions