-
-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@VirtualProperty makes collection null #596
Comments
Can you post the error trace? |
@goetas Updated the post. |
is this a deserialized object that gets re-serialized?
|
This is a normal object. After instantiated by doctrine, it is serialized. BestThings is a one-to-many association. So, I think it should be an ArrayCollection. I have also initiated in the constructor as ArrayCollection. Iniated ArrayCollection with real objects (by doctrine) is serialized successfully without using VirtualProperty. I get JSON array after request. My fault if I don't understand you @goetas . |
|
hmm... weird... you can try to see if the object is a proxy... maybe the serialized did not trigger the proxy initialization... but still weird to me.. |
Hi. I hope to offend nobody to wake an old/stale issue. But I'm affraid to face the same problem without any solution/workaround found yet. The only difference is that the all the entitie's fields are null and not only the collection and as aliemre mentionned, my collection is not empty and none of the entities are null. I pasted the stacktrace on pasatebin. This is an array of CommercialArea with a I use SF4.3 with jms serializer bundle 3.4.1 (jms serializer 3.2.0). This appens during a migration from SF3.4 with jms serializer bundle 2.4.4 (jms serializer 1.14.0) where I had no issues. I hope we can find a solution as this is the only problem blocking me for the migration. I have only 6 virtual properties for now which are commented to work on other parts of the migration and it's a small amount of perperties reguarding the base code but still, this is a major issue for me. Let me know if I can give more info to help. |
Do you have some custom handlers/event-listeners ? this error seems caused by them. Thanks for providing the detailed description for your problem, but unfortunately is still very specific and connected to your application... any chance to extract the issue and create a repository that reproduces the issue independently? (so I can debug it) |
I have listeners but not related to jms. Related to doctrine but not on the entities mentionned. I will try to reproduce on a smaller app but it may take some time. As there will be only three entities, I bet this will work fine. 😈 |
@goetas I managed to create a minimal project. I use the same dependencies (not all only the required ones), same configuration and serialization configuration. The only difference between the small project and mine is the mysql version (5.7 here, 5.6 on my project) but is not relevant here as I was able to reproduce ! Here is the project : https://github.com/flohw/jms_issue Let me know if you can find something! Thanks |
Fixed in schmittjoh/serializer#1126 Was quite a challenge! Thanks to @flohw for the effort in isolating the issue in a reproducible project |
Awesome! I didn't expect a fix so quickly!!! Thank you! |
updating jms/serializer should be enough, no need to update the bundle |
It works just fine when I installed jms/serializer and targeted dev-master. Will you release a new tag soon? The same problem seems to appear with a serialization configuration a bit more complex: App\Entity\SomeEntity:
properties:
marketCharges:
expose: true
serialized_name: marketCharges
type: array<int, App\Entity\MarketCharge>
accessor:
getter: getMarketCharges I think it's only due to the |
See https://github.com/schmittjoh/serializer/releases/tag/3.3.0 |
Did not understand the second part of your message. Did schmittjoh/serializer#1126 solve your issue or not? |
Yes but not everywhere... This both example work: App\Entity\SomeEntity:
properties:
marketCharges:
expose: true
serialized_name: marketCharges
accessor:
getter: getMarketCharges
####
App\Entity\SomeEntity:
virtual_properties:
getMarketCharges:
expose: true
serialized_name: marketCharges These both didn't: App\Entity\SomeEntity:
properties:
marketCharges:
expose: true
serialized_name: marketCharges
type: array<int, App\Entity\MarketCharge>
accessor:
getter: getMarketCharges
######
App\Entity\SomeEntity:
virtual_properties:
getMarketCharges:
expose: true
serialized_name: marketCharges
type: array<int, App\Entity\MarketCharge> |
Can you share the code of |
public function getMarketCharges()
{
// Reindex collection by market id
$charges = new ArrayCollection();
$this->marketCharges->map(function (MarketCharge $marketCharge) use ($charges) {
$charges->set($marketCharge->getMarketId(), $marketCharge);
});
return $charges;
} I think I can return a real php array instead of an ArrayCollection |
Ideed. The serialization works fine but I loss the indexing by |
I have another part of the code where I return a new ArrayCollection too: public function getActivePrices()
{
if (null === $this->activePrices) {
$criteria = Criteria::create()->where(Criteria::expr()->eq('isActive', true));
$this->activePrices = $this->getPrices()->matching($criteria);
}
return $this->activePrices;
} Here the order doesn't matter but I use some |
After some more testing I can confirm that returning a new ArrayCollection produces the error. I hope you can find a solution for that too 🙂 |
If you are returning ArrayCollection or any other "doctrine" collection types, you have to use the right type hint ( |
It works beautifully with Huge thank you again. I didn't expect a fix so quickly! 😀 |
Hi.
I use @VirtualProperty annotation within a method that implements Criteria to filter down results. However, the collection gets null and Symfony throws a FatalErrorException:
Error: Call to a member function matching() on null
Without VirtualProperty, Criteria works normal. Could you help? Thanks in advance.
Stack Trace: (1 Line only)
Restaurant.php
https://gist.github.com/aliemre/8cc4afd39bf612031243f4352a96d8d3
Running Symfony 2.8 and JmsSerializerBundle 1.1.
The text was updated successfully, but these errors were encountered: