serialize tree