Close listener

Added method to close the listener object and a generic ToJSON extension
method