Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does JMS Serializer ignore mappings for nested collections?

I have entities in a OneToMany relation:

Forecast -> has many -> Brick(s)

I've created serialization mappings for each in Resources/config/serializer/Entity.xxx.yml where xxx is entity name.

Each entity has exclusion policy set to ALL and some of it's properties are exposed, eg:

Acme\ForecastBundle\Entity\Forecast:   
  exclusion_policy: ALL   
  xml_root_name: forecast   
  properties:
    id:
      expose: true
      type: integer
    regionUid:
      expose: true
      type: string
    description:
      expose: true
      type: string
    bricks:
      expose: true
      type: array<Acme\ForecastBundle\Entity\Brick>
      xml_list:
        inline: true
        entry_name: brick

When in my template I do {{ forecast|serialize|raw }} I am getting:

Forecast -> as I expected -> only exposed fields are serialized

Bricks collection -> all properties are serialized -> it seems that my Entity.Brick.yml is ignored... why?

In brick I have only ID and name exposed.. but in serialized output I have all properties (created_at, updated_at.. and more).. why? They should be excluded by "exclusion_policy: ALL". It seems that config for nested collection is not used.

Acme\ForecastBundle\Entity\Brick:   
  exclusion_policy: ALL   
  xml_root_name: brick
  properties:
    id:
      expose: true
      type: integer
    name:
      expose: true
      type: string

EDIT:

Yes, I did clear cache after each change in .yml config

After some suggestions I added @ExclusionPolicy("ALL") annotation to the Brick class and @Expose on ID, just to see what happens.. and suddenly it works! Not only ID is exposed, but everything is like in my YML configuration.

So I removed the annotations.. and it still works!

So it seems that adding Annotations somehow forced serializer to recognize my YML config. I don't know why though. That worries me.

Is it possible APC cache is guilty? I did clear Symfony2 cache numerous of times, but APC only a few.

like image 408
ioleo Avatar asked Jan 11 '14 21:01

ioleo


1 Answers

Since there were no anwsers, I'll post what I eventually did/found out (for future reference and anyone who encounters the same problem). I'll quote my edit:

After some suggestions I added @ExclusionPolicy("ALL") annotation to the Brick class and @Expose on ID, just to see what happens.. and suddenly it works! Not only ID is exposed, but everything is like in my YML configuration.

So I removed the annotations.. and it still works!

So it seems that adding Annotations somehow forced serializer to recognize my YML config. I don't know why though. That worries me.

like image 194
ioleo Avatar answered Nov 10 '22 17:11

ioleo