We often reach for tools that solve immediate problems. When it comes to hydrating objects from raw data, many of us see the ObjectMapper component...
For further actions, you may consider blocking this person and/or reporting abuse
And another issue popped up; I'm trying to map an array of objects.
Documentation states: (documentation)
However I'm not able to make this happen, did you?
Weekend project for me) Turning this article into a GitHub repo.
I started a new repo with some test-commands. Test 1, 2, 4 are working, 3 fails, 5 I still have to build. Test 6 probably is a test for trying to fix the name-converter without a decorator. (or maybe perhaps with an decorator)
repo
It's done) github.com/mattleads/SymfonyObject...
Nice! Will have a closer look at it this weekend. But already love the nested object implementation. The posts are not converted into objects, not sure if the transformer is actually triggered.
Updated. Check once more.
I solved everything in a single decorator now. For me it works fine. The objectMapper seems to be good in handling objects, however decoded json it seems not to understand in certain cases but this might improve in the near future.
decorator Thanks for rubberducking/pair programming this!
Hi @mattleads ,
I tried to use the snake_case to CamelCase converter in Symfony 8.0 but I'm not able to make it work. You already tried this? Only way I get to function snake_case combined with CamelCase is by using the
#[Map(source: 'snake_case')]public string $snakeCase,
Thanks in advance! Regards Arthur
All works fine)) Clean Symfony 8.0 installed just for you))
Thanks for your effort! Sorry for the confusion.. That actually works great and that's the way I'm doing it right now. However, I'm trying to implement this name-converter:
serializer.name_converter.snake_case_to_camel_caseAnd I can't get it to work.. Not sure what I'm missing.. Probably it moved to another location (
config/packages/serializer.yaml) but that's in my opinion about serializing and not about object mapping.. So I'm a little confused.But when I get this name-converter to work that will save me a great amount of time :)
I'd suggest to use Decorator))
And no more #Map needed))
Yeah that's also a good option! But that draws me to the conclusion that this configuration via the framework.yaml file with the name_converter isn't working as we expected. Because I would love the implementation. And I tried it in the serializer.yaml file but that also didn't work out.