As Vladimir noted, you can use your own AST node class, which has built-in serialization capabilities. You can also use the tree adapter to create the types of nodes you need.
If you only need serialization and not de-serialization, you might just do:
ast.toStringTree()
LISP. AST node toString(). toStringTree() node toStringTree, , toString. , .