Fix null reference bug in serializer