fix serialization of arrays

previously this code would modify the array if it was
a standard array and a 'count' was passed in. If count
was smaller than the length of the array the source 
array would be chopped. This change might result in a
performance decrease and garbage collection increase
of the serialize method because it now copies the full 
array before changing its size. However, as far as I can 
tell this method is not used on a regular basis so these
issues should not mater.
[#58243476]