You need to break it down to points if they're good points and reconstruct. Polylines are made from paths, polygons are made from rings.
Go through each point on the line adding a point to your output array and then insert.
here's a post that might help Getting all the points of polyline