List of usage examples for org.springframework.data.util ClassTypeInformation OBJECT
ClassTypeInformation OBJECT
To view the source code for org.springframework.data.util ClassTypeInformation OBJECT.
Click Source Link
From source file:org.springframework.data.mongodb.core.convert.MappingMongoConverter.java
/** * Writes the given {@link Map} to the given {@link DBObject} considering the given {@link TypeInformation}. * /*from w ww. j av a 2s .c om*/ * @param obj must not be {@literal null}. * @param dbo must not be {@literal null}. * @param propertyType must not be {@literal null}. * @return */ protected DBObject writeMapInternal(Map<Object, Object> obj, DBObject dbo, TypeInformation<?> propertyType) { for (Map.Entry<Object, Object> entry : obj.entrySet()) { Object key = entry.getKey(); Object val = entry.getValue(); if (conversions.isSimpleType(key.getClass())) { // Don't use conversion service here as removal of ObjectToString converter results in some primitive types not // being convertable String simpleKey = potentiallyEscapeMapKey(key.toString()); if (val == null || conversions.isSimpleType(val.getClass())) { writeSimpleInternal(val, dbo, simpleKey); } else if (val instanceof Collection || val.getClass().isArray()) { dbo.put(simpleKey, writeCollectionInternal(asCollection(val), propertyType.getMapValueType(), new BasicDBList())); } else { DBObject newDbo = new BasicDBObject(); TypeInformation<?> valueTypeInfo = propertyType.isMap() ? propertyType.getMapValueType() : ClassTypeInformation.OBJECT; writeInternal(val, newDbo, valueTypeInfo); dbo.put(simpleKey, newDbo); } } else { throw new MappingException("Cannot use a complex object as a key value."); } } return dbo; }