Serialize the elements of list correctly