/**
  * @param Http\Request\Parameters\Fields $fields
  */
 protected function filterOutResourceFields(Fields $fields)
 {
     if (false === $fields->isEmpty()) {
         foreach ($fields->get() as $type => $properties) {
             foreach ($this->serializationStrategy->getMappings() as $mapping) {
                 if ($mapping->getClassAlias() === $type) {
                     $mapping->setFilterKeys($properties);
                 }
             }
         }
     }
 }
 /**
  * @param Request $request
  */
 private function filterOutResourceFields(Request $request)
 {
     if ($filters = $request->getFields()) {
         foreach ($filters as $type => $properties) {
             foreach ($this->serializationStrategy->getMappings() as $mapping) {
                 if ($mapping->getClassAlias() === $type) {
                     $mapping->setFilterKeys($properties);
                 }
             }
         }
     }
 }
    /**
     *
     */
    public function testItWillSerializeToJsonApiAComplexObjectAndFilterFields()
    {
        $mappings = HelperMapping::complex();
        $mapper = new Mapper($mappings);
        $expected = <<<JSON
{
   "data":{
      "type":"post",
      "id":"9",
      "attributes":{
         "title":"Hello World"
      },
      "links":{
         "self":{
            "href":"http://example.com/posts/9"
         },
         "comments":{
            "href":"http://example.com/posts/9/comments"
         }
      }
   },
   "links":{
      "self":{
         "href":"http://example.com/posts/9"
      },
      "comments":{
         "href":"http://example.com/posts/9/comments"
      }
   },
   "meta":{
      "author":{
         "name":"Nil Portugués Calderó",
         "email":"*****@*****.**"
      },
      "is_devel":true
   },
   "jsonapi":{
      "version":"1.0"
   }
}
JSON;
        $post = HelperFactory::complexPost();
        $transformer = new JsonApiTransformer($mapper);
        $transformer->setMeta(['author' => ['name' => 'Nil Portugués Calderó', 'email' => '*****@*****.**']]);
        $transformer->addMeta('is_devel', true);
        $fields = new Fields();
        $fields->addField('post', 'title');
        $this->assertEquals(\json_decode($expected, true), \json_decode((new JsonApiSerializer($transformer))->serialize($post, $fields), true));
    }