How to get object data as json including object bricks

Hello Pimcore people :slight_smile:

I’m having trouble with getting some clean json from object data.

I have defined a class with some optional object bricks. Created some data objects and filled in some data. Now i want to integrate pimcore with a message queue. The goal is that everytime a data object is updated and published i want to send the data as json to a message queue.

So far i have used the PHP api end the event “onPostUpdate” to hook in when objects are updated. To only get updates that are published I’m checking that object “isPublished” and it’s not a “saveVersionOnly” update.

So far so good.

Here comes the part that I’m struckling with. Maybe because PHP is new to me or maybe I’m going about this the wrong way.

When “onPostUpdate” is raised I’m getting the object that is updated. Serializing this object to json is not that easy. First is followed the help section here:
I made an override for my model and implemented the “JsonSerializable”

That worked great for the properties directly on that class. But object bricks, field collections etc are left out for obvious reasons and it was now clear that if i want the classes to be json serializable i would have to override every generated class and implement “JsonSerializable”. I’m not ready to do all that work just to get the data in a clean format. And it would take out all the dynamic of having generated classes that are updated with a nice UI. I might as well define the classes in code instead of having them generated.

There must be a clean way to get complete object data as json that I am not seeing?