# File lib/dm-serializer/to_json.rb, line 18
    def as_json(options = {})
      options = {} if options.nil?
      result  = {}

      properties_to_serialize(options).each do |property|
        property_name = property.name
        value = __send__(property_name)
        result[property_name] = value.kind_of?(DataMapper::Model) ? value.name : value
      end

      # add methods
      Array(options[:methods]).each do |method|
        next unless respond_to?(method)
        result[method] = __send__(method)
      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]}})
      #
      # TODO: This needs tests and also needs to be ported to #to_xml and
      # #to_yaml
      if options[:relationships]
        options[:relationships].each do |relationship_name, opts|
          if respond_to?(relationship_name)
            result[relationship_name] = __send__(relationship_name).to_json(opts.merge(:to_json => false))
          end
        end
      end

      result
    end