-
-
Notifications
You must be signed in to change notification settings - Fork 960
Closed
Labels
Description
The regression appeared in version 2.4.4. Indeed, the code below is fully functional with version 2.4.3. I've discussed with @teohhanhui on Slack about this issue.
On the image, we can see the inheritance relationship between the different objects. Teachr and Client inherit from User which is an abstract class (codes are below).
There is a relationship between the User and Address objects.
User:
/**
* The User class.
*
* @ORM\Entity()
* @ORM\Table()
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"user" = "User", "client" = "Client", "teachr" = "Teachr"})
*/
abstract class User implements UserInterface
{
/** ... */
/**
* @ORM\OneToMany(targetEntity="App\Entity\Address", cascade={"persist", "remove"}, mappedBy="owner")
* @Groups({"read_client", "read_teachr"})
*/
private $addresses;
}Client (same for Teachr):
/**
* Class for Clients.
*
* @ApiResource()
* @ORM\Entity()
*/
class Client extends User
{
}Address:
/**
* Class Address.
*
* @ApiResource()
* @ORM\Entity()
*/
class Address
{
/** ... */
/**
* @var User Client or Teach'r address owner.
*
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="addresses")
* @Groups({"read_address", "write_address"})
*/
private $owner;
}The error:
{
"@context": "/contexts/Error",
"@type": "hydra:Error",
"hydra:title": "An error occurred",
"hydra:description": "Cannot instantiate abstract class App\\Entity\\User",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
"function": "",
"file": "/var/www/html/vendor/symfony/serializer/Normalizer/AbstractNormalizer.php",
"line": 452,
"args": []
},
{
"namespace": "",
"short_class": "ReflectionClass",
"class": "ReflectionClass",
"type": "->",
"function": "newInstanceArgs",
"file": "/var/www/html/vendor/symfony/serializer/Normalizer/AbstractNormalizer.php",
"line": 452,
"args": [
[
"array",
[]
]
]
},
{
"namespace": "Symfony\\Component\\Serializer\\Normalizer",
"short_class": "AbstractNormalizer",
"class": "Symfony\\Component\\Serializer\\Normalizer\\AbstractNormalizer",
"type": "->",
"function": "instantiateObject",
"file": "/var/www/html/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php",
"line": 182,
"args": [
[
"array",
[
[
"string",
"/clients/1"
]
]
],
[
"string",
"App\\Entity\\User"
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"write_address"
]
]
],
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/addresses"
],
"uri": [
"string",
"http://localhost:8082/addresses"
],
"api_denormalize": [
"boolean",
true
],
"cache_key": [
"string",
"2d51165683a23cc89b05ec2cfbca3ff3"
]
}
],
[
"object",
"ReflectionClass"
],
[
"array",
[]
],
[
"string",
"jsonld"
]
]
},
{
"namespace": "Symfony\\Component\\Serializer\\Normalizer",
"short_class": "AbstractObjectNormalizer",
"class": "Symfony\\Component\\Serializer\\Normalizer\\AbstractObjectNormalizer",
"type": "->",
"function": "instantiateObject",
"file": "/var/www/html/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php",
"line": 283,
"args": [
[
"array",
[
[
"string",
"/clients/1"
]
]
],
[
"string",
"App\\Entity\\User"
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"write_address"
]
]
],
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/addresses"
],
"uri": [
"string",
"http://localhost:8082/addresses"
],
"api_denormalize": [
"boolean",
true
],
"cache_key": [
"string",
"2d51165683a23cc89b05ec2cfbca3ff3"
]
}
],
[
"object",
"ReflectionClass"
],
[
"array",
[]
],
[
"string",
"jsonld"
]
]
},
{
"namespace": "Symfony\\Component\\Serializer\\Normalizer",
"short_class": "AbstractObjectNormalizer",
"class": "Symfony\\Component\\Serializer\\Normalizer\\AbstractObjectNormalizer",
"type": "->",
"function": "denormalize",
"file": "/var/www/html/vendor/symfony/serializer/Serializer.php",
"line": 191,
"args": [
[
"string",
"/clients/1"
],
[
"string",
"App\\Entity\\User"
],
[
"string",
"jsonld"
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"write_address"
]
]
],
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/addresses"
],
"uri": [
"string",
"http://localhost:8082/addresses"
],
"api_denormalize": [
"boolean",
true
],
"cache_key": [
"string",
"2d51165683a23cc89b05ec2cfbca3ff3"
]
}
]
]
},
{
"namespace": "Symfony\\Component\\Serializer",
"short_class": "Serializer",
"class": "Symfony\\Component\\Serializer\\Serializer",
"type": "->",
"function": "denormalize",
"file": "/var/www/html/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
"line": 690,
"args": [
[
"string",
"/clients/1"
],
[
"string",
"App\\Entity\\User"
],
[
"string",
"jsonld"
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"write_address"
]
]
],
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/addresses"
],
"uri": [
"string",
"http://localhost:8082/addresses"
],
"api_denormalize": [
"boolean",
true
],
"cache_key": [
"string",
"2d51165683a23cc89b05ec2cfbca3ff3"
]
}
]
]
},
{
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
"type": "->",
"function": "createAttributeValue",
"file": "/var/www/html/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
"line": 350,
"args": [
[
"string",
"owner"
],
[
"string",
"/clients/1"
],
[
"string",
"jsonld"
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"write_address"
]
]
],
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/addresses"
],
"uri": [
"string",
"http://localhost:8082/addresses"
],
"api_denormalize": [
"boolean",
true
],
"cache_key": [
"string",
"2d51165683a23cc89b05ec2cfbca3ff3"
]
}
]
]
},
{
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
"type": "->",
"function": "setAttributeValue",
"file": "/var/www/html/vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php",
"line": 300,
"args": [
[
"object",
"App\\Entity\\Address"
],
[
"string",
"owner"
],
[
"string",
"/clients/1"
],
[
"string",
"jsonld"
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"write_address"
]
]
],
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Entity\\Address"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/addresses"
],
"uri": [
"string",
"http://localhost:8082/addresses"
],
"api_denormalize": [
"boolean",
true
],
"cache_key": [
"string",
"2d51165683a23cc89b05ec2cfbca3ff3"
]
}
]
]
},
{
"namespace": "Symfony\\Component\\Serializer\\Normalizer",
"short_class": "AbstractObjectNormalizer",
"class": "Symfony\\Component\\Serializer\\Normalizer\\AbstractObjectNormalizer",
"type": "->",
"function": "denormalize",
"file": "/var/www/html/vendor/api-platform/core/src/Serializer/AbstractItemNormalizer.php",
"line": 219,
"args": [
[
"array",
{
"googlePlaceId": [
"string",
"string"
],
"sessionToken": [
"string",
"string"
],
"houseCode": [
"string",
"string"
],
"extraInformation": [
"string",
"string"
],
"owner": [
"string",
"/clients/1"
]
}
],
[
"string",
"App\\Entity\\Address"
],
[
"string",
"jsonld"
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"write_address"
]
]
],
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Entity\\Address"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/addresses"
],
"uri": [
"string",
"http://localhost:8082/addresses"
],
"api_denormalize": [
"boolean",
true
],
"cache_key": [
"string",
"2d51165683a23cc89b05ec2cfbca3ff3"
]
}
]
]
},
{
"namespace": "ApiPlatform\\Core\\Serializer",
"short_class": "AbstractItemNormalizer",
"class": "ApiPlatform\\Core\\Serializer\\AbstractItemNormalizer",
"type": "->",
"function": "denormalize",
"file": "/var/www/html/vendor/api-platform/core/src/JsonLd/Serializer/ItemNormalizer.php",
"line": 117,
"args": [
[
"array",
{
"googlePlaceId": [
"string",
"string"
],
"sessionToken": [
"string",
"string"
],
"houseCode": [
"string",
"string"
],
"extraInformation": [
"string",
"string"
],
"owner": [
"string",
"/clients/1"
]
}
],
[
"string",
"App\\Entity\\Address"
],
[
"string",
"jsonld"
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"write_address"
]
]
],
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Entity\\Address"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/addresses"
],
"uri": [
"string",
"http://localhost:8082/addresses"
],
"api_denormalize": [
"boolean",
true
]
}
]
]
},
{
"namespace": "ApiPlatform\\Core\\JsonLd\\Serializer",
"short_class": "ItemNormalizer",
"class": "ApiPlatform\\Core\\JsonLd\\Serializer\\ItemNormalizer",
"type": "->",
"function": "denormalize",
"file": "/var/www/html/vendor/symfony/serializer/Serializer.php",
"line": 191,
"args": [
[
"array",
{
"googlePlaceId": [
"string",
"string"
],
"sessionToken": [
"string",
"string"
],
"houseCode": [
"string",
"string"
],
"extraInformation": [
"string",
"string"
],
"owner": [
"string",
"/clients/1"
]
}
],
[
"string",
"App\\Entity\\Address"
],
[
"string",
"jsonld"
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"write_address"
]
]
],
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Entity\\Address"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/addresses"
],
"uri": [
"string",
"http://localhost:8082/addresses"
]
}
]
]
},
{
"namespace": "Symfony\\Component\\Serializer",
"short_class": "Serializer",
"class": "Symfony\\Component\\Serializer\\Serializer",
"type": "->",
"function": "denormalize",
"file": "/var/www/html/vendor/symfony/serializer/Serializer.php",
"line": 142,
"args": [
[
"array",
{
"googlePlaceId": [
"string",
"string"
],
"sessionToken": [
"string",
"string"
],
"houseCode": [
"string",
"string"
],
"extraInformation": [
"string",
"string"
],
"owner": [
"string",
"/clients/1"
]
}
],
[
"string",
"App\\Entity\\Address"
],
[
"string",
"jsonld"
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"write_address"
]
]
],
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Entity\\Address"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/addresses"
],
"uri": [
"string",
"http://localhost:8082/addresses"
]
}
]
]
},
{
"namespace": "Symfony\\Component\\Serializer",
"short_class": "Serializer",
"class": "Symfony\\Component\\Serializer\\Serializer",
"type": "->",
"function": "deserialize",
"file": "/var/www/html/vendor/api-platform/core/src/EventListener/DeserializeListener.php",
"line": 100,
"args": [
[
"array",
{
"googlePlaceId": [
"string",
"string"
],
"sessionToken": [
"string",
"string"
],
"houseCode": [
"string",
"string"
],
"extraInformation": [
"string",
"string"
],
"owner": [
"string",
"/clients/1"
]
}
],
[
"string",
"App\\Entity\\Address"
],
[
"string",
"jsonld"
],
[
"array",
{
"groups": [
"array",
[
[
"string",
"write_address"
]
]
],
"operation_type": [
"string",
"collection"
],
"collection_operation_name": [
"string",
"post"
],
"api_allow_update": [
"boolean",
false
],
"resource_class": [
"string",
"App\\Entity\\Address"
],
"input": [
"null",
null
],
"output": [
"null",
null
],
"request_uri": [
"string",
"/addresses"
],
"uri": [
"string",
"http://localhost:8082/addresses"
]
}
]
]
},
{
"namespace": "ApiPlatform\\Core\\EventListener",
"short_class": "DeserializeListener",
"class": "ApiPlatform\\Core\\EventListener\\DeserializeListener",
"type": "->",
"function": "onKernelRequest",
"file": "/var/www/html/vendor/symfony/event-dispatcher/Debug/WrappedListener.php",
"line": 115,
"args": [
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher"
]
]
},
{
"namespace": "Symfony\\Component\\EventDispatcher\\Debug",
"short_class": "WrappedListener",
"class": "Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener",
"type": "->",
"function": "__invoke",
"file": "/var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php",
"line": 212,
"args": [
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher"
]
]
},
{
"namespace": "Symfony\\Component\\EventDispatcher",
"short_class": "EventDispatcher",
"class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
"type": "->",
"function": "doDispatch",
"file": "/var/www/html/vendor/symfony/event-dispatcher/EventDispatcher.php",
"line": 44,
"args": [
[
"array",
[
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
],
[
"object",
"Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener"
]
]
],
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"
]
]
},
{
"namespace": "Symfony\\Component\\EventDispatcher",
"short_class": "EventDispatcher",
"class": "Symfony\\Component\\EventDispatcher\\EventDispatcher",
"type": "->",
"function": "dispatch",
"file": "/var/www/html/vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php",
"line": 145,
"args": [
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"
]
]
},
{
"namespace": "Symfony\\Component\\EventDispatcher\\Debug",
"short_class": "TraceableEventDispatcher",
"class": "Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher",
"type": "->",
"function": "dispatch",
"file": "/var/www/html/vendor/symfony/http-kernel/HttpKernel.php",
"line": 126,
"args": [
[
"string",
"kernel.request"
],
[
"object",
"Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent"
]
]
},
{
"namespace": "Symfony\\Component\\HttpKernel",
"short_class": "HttpKernel",
"class": "Symfony\\Component\\HttpKernel\\HttpKernel",
"type": "->",
"function": "handleRaw",
"file": "/var/www/html/vendor/symfony/http-kernel/HttpKernel.php",
"line": 67,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
],
[
"integer",
1
]
]
},
{
"namespace": "Symfony\\Component\\HttpKernel",
"short_class": "HttpKernel",
"class": "Symfony\\Component\\HttpKernel\\HttpKernel",
"type": "->",
"function": "handle",
"file": "/var/www/html/vendor/symfony/http-kernel/Kernel.php",
"line": 198,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
],
[
"integer",
1
],
[
"boolean",
true
]
]
},
{
"namespace": "Symfony\\Component\\HttpKernel",
"short_class": "Kernel",
"class": "Symfony\\Component\\HttpKernel\\Kernel",
"type": "->",
"function": "handle",
"file": "/var/www/html/public/index.php",
"line": 25,
"args": [
[
"object",
"Symfony\\Component\\HttpFoundation\\Request"
]
]
}
]
}By the way, thank you for this wonderful framework ❤️
Reactions are currently unavailable
