(PHP) Symfony Serializer Component For Array of Objects

46 views Asked by At

Currently, I have a couple of Soap services that I interact with. Every so often, the request fails and I decided to start storing the request data, request XML, response, etc so I can fix it and resend it after I fix the issue. That way, I don't lose that request.

I'm serializing an object that contains objects and arrays. (Changing names to random object names for example purposes).

Example:

Object: ErrorObject
 (- InfoObject -)
 property#1: info (InfoObject)
 (- Array -)
 property#2: individuals (NurseObject|SurgeonObject|etc)
  'info' => InfoObject (Serializes/Deserializes with no issues)
  'individuals'  => [
    0 => SurgeonObject,
    1 => NurseObject#1,
    2 => NurseObject#2
    3 => etc
    ...
  ]

Logic is already in place to know what to do with each of these individuals objects but when I try to deserialize them, it returns arrays of information for each instead of the data within the specific object. I assume here that I have to use a bit more complex normalizers but I haven't used any aside from the default yet.

The serialization code is very simple: $this->serializer->serialize(ErrorObject, 'json')

Deserialization code: $this-serializer->deserialize($data, ErrorObject, 'json')


Expecting to be able to get the individuals in their appropriate object filled with the data to be able to rebuild the xml back. How can I use the Symfony Serializer to accomplish this?

Thank you in advance!

0

There are 0 answers