Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Warning: array_key_exists() expects parameter 2 to be array, string given #70

Closed
winks opened this issue Mar 28, 2013 · 8 comments
Closed

Comments

@winks
Copy link

winks commented Mar 28, 2013

Hello,
I was sending some JSON like

    {"success":true,"message":"OK","data":{"id":15,"foo":23,"campaign":"ASDF","campaign_id":1}}

and got this:

Warning: array_key_exists() expects parameter 2 to be array, string given in /srv/www/vendor/jms/serializer/src/JMS/Serializer/GenericDeserializationVisitor.php line 165

When I stop sending "campaign", only "campaign_id" it seems to work.

It might very well be that I missed something, or using it wrong, but this patch might be useful anyway :)

--- vendor/jms/serializer/src/JMS/Serializer/GenericDeserializationVisitor.php.old  2013-03-28 16:02:37.909925723 +0100
+++ vendor/jms/serializer/src/JMS/Serializer/GenericDeserializationVisitor.php  2013-03-28 16:01:37.640657807 +0100
@@ -161,7 +161,7 @@
     public function visitProperty(PropertyMetadata $metadata, $data)
     {
         $name = $this->namingStrategy->translateName($metadata);
-        if (null === $data || ! array_key_exists($name, $data)) {
+        if (null === $data || !is_array($data) || ! array_key_exists($name, $data)) {
             return;
         }
@sprain
Copy link

sprain commented Jun 11, 2013

Same problem here …

@sprain
Copy link

sprain commented Jun 11, 2013

Fixed it!
I had a wrong serializer type in my annotations.

I had this:

/**
     * @Serializer\Type("array<Acme\Bundle\BaseBundle\Entity\Host>")
     * @Serializer\Groups({"details"})
     */
    private $host;

When it should have been this:

/**
     * @Serializer\Type("Acme\Bundle\BaseBundle\Entity\Host")
     * @Serializer\Groups({"details"})
     */
    private $host;

Hope this will be helpful for somebody else, too.

@tquiroga
Copy link

tquiroga commented Jul 4, 2013

Same problem for me, I checked my @Serializer\Type it looks fine...

@Tobion
Copy link
Contributor

Tobion commented Jul 19, 2013

I also get this error from time to time. Probably when the the serialization annotation changes but you feed it with old data. So in this case an error is understandable. But it should probably be a little more fault-tolerant or give a better error message instead of a php warning.

@Tobion
Copy link
Contributor

Tobion commented Nov 30, 2013

Duplicate of #110

@oshanz
Copy link

oshanz commented Dec 22, 2015

@sprain +1

@hasmo
Copy link

hasmo commented Dec 29, 2015

I can confirm that I had the same problem as mentioned in #110:

Used:

 <type><![CDATA[ArrayCollection<My\Namespace\Class\Name>]]></type>

Instead of:

 <property name="foo" type="My\Namespace\Class\Name" serialized-name="foo">

@goetas
Copy link
Collaborator

goetas commented Oct 23, 2016

solved with #398

@goetas goetas closed this as completed Oct 23, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants