Skip to content

Denormalizer with SerializedPath: Cannot read property "grid" from an array. Maybe you intended to write the property path as "[grid]" instead. #58572

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

Closed
maMykola opened this issue Oct 15, 2024 · 5 comments

Comments

@maMykola
Copy link

maMykola commented Oct 15, 2024

Symfony version(s) affected

6.4.12

Description

Using object notation in serialized path results in a Cannot read property ...:

Cannot read property "grid" from an array. Maybe you intended to write the property path as "[grid]" instead.

How to reproduce

Clone the repository, then install all dependencies and run the command app:denormalize

git clone https://github.com/maMykola/symfony-denormalizer-serialized-path
cd symfony-denormalizer-serialized-path
composer install
bin/console app:denormalize

Actual result

[critical] Error thrown while running command "app:denormalize". Message: "Cannot read property "grid" from an array. Maybe you intended to write the property path as "[grid]" instead."

In PropertyAccessor.php line 397:
                                                                                                                 
  Cannot read property "grid" from an array. Maybe you intended to write the property path as "[grid]" instead.  
                                                                                                                 

app:denormalize

Expected result

App\Model\Main {#313
  +id: 25
  +attributes: App\Model\Attributes {#5174
    +title: "Attribute"
    +columns: array:3 [
      0 => "one"
      1 => "two"
      2 => "three"
    ]
  }
}

Possible Solution

No response

Additional Context

No response

@eliasfernandez
Copy link
Contributor

@maMykola
Copy link
Author

Looks like the offending line is

maMykola/symfony-denormalizer-serialized-path@e1986d7#diff-b3c12de16f2774d6bfd053742a58792ed725f7a0fe50da878c0aa9e380c3a3deR46

Where you decode the json as object instead of an associative array: https://www.php.net/manual/en/function.json-decode.php

but when the object notation can be used? in which cases?

In my another project I have an stdClass object on input. I'm not sure if it's good idea to convert it to array somehow.

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Friendly reminder that this issue exists. If I don't hear anything I'll close this.

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

@carsonbot carsonbot closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants