# Zend Hal with protected object member

**URL:** <https://discourse.laminas.dev/t/zend-hal-with-protected-object-member/1008>\
**Category:** Mezzio\
**Tags:** zend-expressive-hal\
**Created:** [March 26, 2019, 11:21am UTC](https://discourse.laminas.dev/t/zend-hal-with-protected-object-member/1008 "2019-03-26T11:21:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmuhasan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/mmuhasan/32/454_2.png) [@mmuhasan](https://discourse.laminas.dev/u/mmuhasan)\
**Post date:** [March 26, 2019, 11:21am UTC](https://discourse.laminas.dev/t/zend-hal-with-protected-object-member/1008/1 "2019-03-26T11:21:34Z")

</div>

I am new in Zend framework, and trying to use HAL for API response generation. In the following is a simpler situation of my issues.

The class:

```auto
class Version
{
    protected $data;

    public function __construct($ar){
        $data = $ar;
    }

    public function getArrayCopy(){
        return $data;
    }
}
$obj = new version(['major'=>1,'minor'=>2,'fix'=>3]);

```

When I test with hydrator, it works well as per the following:

```auto
use Zend\Hydrator\ArraySerializableHydrator;

$hydrator = new ArraySerializableHydrator();
$data = $hydrator->extract($obj);

print_r($data); // outputs ['major'=>1,'minor'=>2,'fix'=>3]

```

My HAL configuration is following:

```auto
MetadataMap::class => [
    [
        ' __class__' => RouteBasedResourceMetadata::class,
        'resource_class' => Version::class,
        'route' => 'version',
        'extractor' => ArraySerializableHydrator::class,
    ],
]

```

I use the following line in my Zend expressive (version 3) request handler

```auto
$resource = $this->resourceGenerator->fromObject($obj, $request);
$res = $this->responseFactory->createResponse($request, $resource);

```

The link is generated correctly, but the meta data (version info) is coming as empty. Any help will be much appreciated.

N.B.: My real code is complex, here I tried to generate a simpler version of the issue.

---

<div class="post-metadata">

**Author:** ![matthew](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/matthew/32/14_2.png) [@matthew](https://discourse.laminas.dev/u/matthew)\
**Post date:** [March 26, 2019, 1:42pm UTC](https://discourse.laminas.dev/t/zend-hal-with-protected-object-member/1008/2 "2019-03-26T13:42:54Z")

</div>

Can you provide some sample output, please? Also, what is `$obj` in your above example — a `Version` instance? or something else?

---

<div class="post-metadata">

**Author:** ![mmuhasan](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/mmuhasan/32/454_2.png) [@mmuhasan](https://discourse.laminas.dev/u/mmuhasan)\
**Post date:** [April 4, 2019, 4:09pm UTC](https://discourse.laminas.dev/t/zend-hal-with-protected-object-member/1008/3 "2019-04-04T16:09:53Z")

</div>

I have fixed it. There was a different issue in my configuration and that was actually causing the problem. Thanks for your support
