move json serialization to a separate method to ease subclassing and implementing custom serializers