private function toStdClass(Resource $resource, $customData = false)
 {
     if ($resource instanceof \Stormpath\Resource\CustomData) {
         $customData = true;
     }
     $propertyNames = $resource->getPropertyNames(true);
     $properties = new \stdClass();
     foreach ($propertyNames as $name) {
         $property = $resource->getProperty($name);
         $nameIsCustomData = $name == CustomData::CUSTOMDATA_PROP_NAME;
         if ($property instanceof \Stormpath\Resource\CustomData) {
             $property = $this->toStdClass($property, true);
         } else {
             if ($property instanceof \stdClass && $customData === false && !$nameIsCustomData) {
                 $property = $this->toSimpleReference($name, $property);
             } else {
                 if ($property instanceof \Stormpath\Resource\Resource) {
                     $property = $this->toStdClass($property);
                 }
             }
         }
         $properties->{$name} = $property;
     }
     return $properties;
 }