# File lib/dm-serializer/to_json.rb, line 10
    def to_json(*args)
      options = args.first || {}

      result = {}

      propset = properties_to_serialize(options)

      propset.each do |property|
        result[property.name] = send(property.name)
      end

      # add methods
      (options[:methods] || []).each do |meth|
        if self.respond_to?(meth)
          result[meth] = send(meth)
        end
      end

      # Note: if you want to include a whole other model via relation, use :methods
      # comments.to_json(:relationships=>{:user=>{:include=>[:first_name],:methods=>[:age]}})
      # add relationships
      # TODO: This needs tests and also needs to be ported to #to_xml and #to_yaml
      (options[:relationships] || {}).each do |rel,opts|
        if self.respond_to?(rel)
          result[rel] = send(rel).to_json(opts.merge(:to_json => false))
        end
      end

      # default to making JSON
      if options.fetch(:to_json, true)
        result.to_json
      else
        result
      end
    end