Fix templates to generate cpp code correctly when there are lists

Change-Id: Ia8516a9f5a605df3034ab11548e18b7b2233f7f6
Simplify cpp constructor serialization code template

Change-Id: Icea5a65a1bd3c387ea6094d4ed1068a7f5fd9613