public function getFieldsData()
    {
        $fieldsData = array();
        foreach ($this->getFields() as $field) {
            $fieldData = $this->$field;
            // If the field is an Entity, decode it.
            if ($fieldData instanceof self) {
                $fieldData = $fieldData->getFieldsData();
            } elseif (@reset($fieldData) instanceof Entity) {
                // If the field is an array of Entity, decode them all.
                $newFieldData = array();
                foreach ($fieldData as $key => $entity) {
                    $newFieldData[$key] = $entity->getFieldsData();
                }
                $fieldData = $newFieldData;
            }

            $fieldsData[$field] = $fieldData;
        }

        return $fieldsData;
    }