Format MongoMapper class object.
------------------------------------------------------------------------------
497275
def awesome_mongo_mapper_class(object)
      return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:keys)

      data = object.keys.sort.inject(::ActiveSupport::OrderedHash.new) do |hash, c|
        hash[c.first] = (c.last.type || 'undefined').to_s.underscore.intern
        hash
      end

      # Add in associations
      if @options[:mongo_mapper][:show_associations]
        object.associations.each do |name, assoc|
          data[name.to_s] = assoc
        end
      end

      name = "class #{awesome_simple(object.to_s, :class)}"
      base = "< #{awesome_simple(object.superclass.to_s, :class)}"

      [name, base, awesome_hash(data)].join(' ')
    end
689067
def map_collection(func, collection):
    
    datatype = type(collection)
    if isinstance(collection, Mapping):
        return datatype((key, func(val)) for key, val in collection.items())
    if is_string(collection):
        return collection
    elif isinstance(collection, Iterable):
        return datatype(map(func, collection))
    else:
        return collection
619752
private function createMap(string $class, $object)
    {
        $rule = $this->rules[$class];
        $reflectionObject = new \ReflectionObject($object);
        $result = [];

        foreach ($rule->getMap() as $property => $key) {
            $reflectionProperty = $reflectionObject->getProperty($property);
            $reflectionProperty->setAccessible(true);

            $serializer = $rule->getSerializer($property);

            $result[$key] = is_callable($serializer)
                ? $serializer($reflectionProperty->getValue($object))
                : $reflectionProperty->getValue($object);
        }

        return $result;
    }
744600
public <T> T convert(Object object, Class<T> clazz) {
        if (object == null) {
            return null;
        }

        return mapper.convertValue(object, clazz);
    }
71848
public static Object serializeField(ObjectMapper objectMapper, Object value) {
        if (value == null || BASIC_TYPES.contains(value.getClass())) {
            // Return as is
            return value;
        } else if (value instanceof DBObject) {
            return serializeFields(objectMapper, (DBObject) value);
        } else if (value instanceof Collection) {
            Collection<?> coll = (Collection<?>) value;
            List<Object> copy = null;
            int position = 0;
            for (Object item : coll) {
                Object returned = serializeField(objectMapper, item);
                if (returned != item) {
                    if (copy == null) {
                        copy = new ArrayList<Object>(coll);
                    }
                    copy.set(position, returned);
                }
                position++;
            }
            if (copy != null) {
                return copy;
            } else {
                return coll;
            }
        } else if (value.getClass().isArray()) {
            if (BASIC_TYPES.contains(value.getClass().getComponentType())) {
                return value;
            }
            Object[] array = (Object[]) value;
            Object[] copy = null;
            for (int i = 0; i < array.length; i++) {
                Object returned = serializeField(objectMapper, array[i]);
                if (returned != array[i]) {
                    if (copy == null) {
                        copy = new Object[array.length];
                        System.arraycopy(array, 0, copy, 0, array.length);
                    }
                    copy[i] = returned;
                }
            }
            if (copy != null) {
                return copy;
            } else {
                return array;
            }
        } else {
            // We don't know what it is, serialise it
            BsonObjectGenerator generator = new BsonObjectGenerator();
            try {
                objectMapper.writeValue(generator, value);
            } catch (JsonMappingException e) {
                throw new MongoJsonMappingException(e);
            } catch (IOException e) {
                throw new RuntimeException("Somehow got an IOException writing to memory", e);
            }
            return generator.getValue();
        }
    }
1235764
public function denormalize($data, $class, $format = null, array $context = array())
    {
        preg_match(static::REGEX, $data, $parts);

        $format = '';
        $format .= !empty($parts['date']) ? 'Y-m-d' : '';
        $format .= !empty($parts['tsep']) ? str_replace('T', '\T', $parts['tsep']) : '';
        $format .= !empty($parts['time']) ? 'H:i:s' : '';
        $format .= !empty($parts['usec']) ? '.u' : '';
        $format .= !empty($parts['zsep']) ? ' ' : '';
        $format .= !empty($parts['zone']) ? (($parts['zone'][3] === ':') ? 'P' : 'O') : '';

        $object = \DateTime::createFromFormat($format, $data);
        if ($object === false) {
            throw new \InvalidArgumentException('The provided data or format are not valid.');
        }

        return $object;
    }
830781
def format_obj( obj )
    case obj
    when String; obj
    when Exception
      lines = ["<#{obj.class.name}> #{obj.message}"]
      lines.concat(obj.backtrace) if backtrace? && obj.backtrace
      format_cause(obj, lines)
      lines.join("\n\t")
    when nil; "<#{obj.class.name}> nil"
    else
      str = "<#{obj.class.name}> "
      str << case @obj_format
             when :inspect; obj.inspect
             when :yaml; try_yaml(obj)
             when :json; try_json(obj)
             else obj.to_s end
      str
    end
  end
188665
private Map<Class<?>, Formatter> findFormatMethods()
    {
        final Map<Class<?>, Formatter> formats = new HashMap<Class<?>, Formatter>();
        for (Method method : this.getClass().getMethods())
        {
            Format formatAnnotation = method.getAnnotation(Format.class);
            if (formatAnnotation != null)
            {
                Class<?>[] parameterTypes = method.getParameterTypes();
                if (parameterTypes.length == 0)
                {
                    throw new InvalidFormatMethodException(getClass(), method, "Format methods must take at least 1 parameter!");
                }
                formats.put(parameterTypes[0], createFormatter(method, parameterTypes, formatAnnotation.value()));
            }
        }
        return formats;
    }
380676
def format(object, type = nil)
      core_class = cast(object, type)
      awesome = if core_class != :self
        send(:"awesome_#{core_class}", object) # Core formatters.
      else
        awesome_self(object, type) # Catch all that falls back to object.inspect.
      end
      awesome
    end
1350456
private void writeMapComplex(SerIterator itemIterator) throws IOException {
        output.writeObjectStart();
        while (itemIterator.hasNext()) {
            itemIterator.next();
            Object key = itemIterator.key();
            if (key == null) {
                throw new IllegalArgumentException("Unable to write map key as it cannot be null");
            }
            String str = settings.getConverter().convertToString(itemIterator.key());
            if (str == null) {
                throw new IllegalArgumentException("Unable to write map key as it cannot be a null string");
            }
            output.writeObjectKey(str);
            writeObject(itemIterator.valueType(), itemIterator.value(), itemIterator);
        }
        output.writeObjectEnd();
    }
255205
function createUriQueryMapper (query) {
  var parameters = extractQueryParameters(query);
  return (queryValues, args) => {
    queryValues = queryValues || Object.create(null);

    Object.keys(queryValues)
      .forEach(queryKey => {
        var parameter = parameters[queryKey];

        if (!parameter) {
          return;
        }

        var value = util.isArray(queryValues[queryKey]) ?
          queryValues[queryKey]
            .map(parameter.map)
            .filter(value => value !== null) :
          parameter.map(queryValues[queryKey]);

        if (value === null) {
          return;
        }

        args[parameter.name] = value;
      });
  };
}
1332798
def clean_map(obj: Mapping[Any, Any]) -> Mapping[Any, Any]:
    
    return {k: v for k, v in obj.items() if v is not None}
1047251
function format(input, level, options) {
  if (util.isArray(input)) {
    return array(input, level, options);
  } else if (util.isObject(input)) {
    return object(input, level, options);
  } else {
    return stringify(input, options);
  }
}
484476
private String formatObject(Object obj) {
        if (obj == null) {
            return null;
        }

        if (obj instanceof Number) {
            return NumberFormat.getInstance(locale).format(obj); // fix
        } else if (obj instanceof Date) {
            return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale).format(obj); //fix
        } else if (obj instanceof String) {
            return (String) obj;
        }

        return obj.toString();
    }
1164284
function Mapper(mapper, flusher) {
  Transform.call(this, {
    objectMode: true,
    // Patch from 0.11.7
    // https://github.com/joyent/node/commit/ba72570eae938957d10494be28eac28ed75d256f
    highWaterMark: 16
  })

  this.mapper = mapper
  this.flusher = flusher
}
284938
def pretty_format(obj, indent=None):
        
        if indent is None:
            if isinstance(obj, TLObject):
                obj = obj.to_dict()

            if isinstance(obj, dict):
                return '{}({})'.format(obj.get('_', 'dict'), ', '.join(
                    '{}={}'.format(k, TLObject.pretty_format(v))
                    for k, v in obj.items() if k != '_'
                ))
            elif isinstance(obj, str) or isinstance(obj, bytes):
                return repr(obj)
            elif hasattr(obj, '__iter__'):
                return '[{}]'.format(
                    ', '.join(TLObject.pretty_format(x) for x in obj)
                )
            else:
                return repr(obj)
        else:
            result = []
            if isinstance(obj, TLObject):
                obj = obj.to_dict()

            if isinstance(obj, dict):
                result.append(obj.get('_', 'dict'))
                result.append('(')
                if obj:
                    result.append('\n')
                    indent += 1
                    for k, v in obj.items():
                        if k == '_':
                            continue
                        result.append('\t' * indent)
                        result.append(k)
                        result.append('=')
                        result.append(TLObject.pretty_format(v, indent))
                        result.append(',\n')
                    result.pop()  # last ',\n'
                    indent -= 1
                    result.append('\n')
                    result.append('\t' * indent)
                result.append(')')

            elif isinstance(obj, str) or isinstance(obj, bytes):
                result.append(repr(obj))

            elif hasattr(obj, '__iter__'):
                result.append('[\n')
                indent += 1
                for x in obj:
                    result.append('\t' * indent)
                    result.append(TLObject.pretty_format(x, indent))
                    result.append(',\n')
                indent -= 1
                result.append('\t' * indent)
                result.append(']')

            else:
                result.append(repr(obj))

            return ''.join(result)
507496
function _mapObject(data, schema, options) {
    return Object
        .keys(schema)
        .reduce(function (memo, key) {
            memo[key] = _mapDataValue(data, schema[key]);
            return memo;
        }, options.keep ? _clone(data) : {});
}