Writer calls toJSON on attachments if it is a function