Skip to content
Advertisement

Symfony 4 custom deserializer returns empty properties in entity

I have a custom Symfony 4 deserializer

JavaScript

The way I’m deserializing is pretty straight forward:

JavaScript

However, I get this result returned:

JavaScript

Now, if I were to do a dump, just before the return in the decode part of the decoder, I’d get this:

JavaScript

Ignoring the not set properties(which I’m fine with), it should work quite nicely, but it doesn’t.

For the life of me I can’t figure out what’s wrong.

Any help is appreciated.

Advertisement

Answer

You are thinking way to complicated.

Tested, working example:
Your entity – take a closer look at the end – we need setters with the names of your array keys:

JavaScript

Simple Controller to test the Output:

JavaScript

Output: enter image description here

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement