Why serialise out the algebra at all?
If your aim is to walk the algebra tree and extract the BGPs then you can do this using the OpVisitor
interface of which there are various implementations of that will get you started. The particular method you would care about is visit(OpBgp opBgp)
since then you can access the methods of the OpBgp
class to extract the pattern information