I sourced out the answer to my question!.
One simple cannot do:
$my_custom_object = array("Key1" => "value!")
OR
$my_custom_object = json_encode(array("Key1" => "value!"));
It expect the value to be an object:
So setting customAttribute like so:
$extensionAttributes->setOurCustomData($ourCustomData);
$ourCustomData
Must be an object:
So I create Interface with getter and setter and a model that implements the interface and in extension_attributes.xml
:
...
<attribute code="our_custom_data" type="Vendor\Module\Api\Data\CustomInterface"/>
...
In Plugin orderRepository:
Inject model : \Vendor\Module\Model\CustomModel $customModel
...
$ourCustomData = $this->customModel;
$extensionAttributes->setOurCustomData($ourCustomData);
...
Hope it helps anyone!