serialization stackoverflow fix

Generic typing here.