/** * Root entry method into write conversion. Adds a type discriminator to the {@link Document}. Shouldn't be called for * nested conversions. * * @see org.springframework.data.mongodb.core.convert.MongoWriter#write(java.lang.Object, com.mongodb.Document) */ public void write(Object obj, Bson bson) { if (null == obj) { return; } Class<?> entityType = ClassUtils.getUserClass(obj.getClass()); TypeInformation<? extends Object> type = ClassTypeInformation.from(entityType); Object target = obj instanceof LazyLoadingProxy ? ((LazyLoadingProxy) obj).getTarget() : obj; writeInternal(target, bson, type); if (asMap(bson).containsKey("_id") && asMap(bson).get("_id") == null) { removeFromMap(bson, "_id"); } if (requiresTypeHint(entityType)) { typeMapper.writeType(type, bson); } }
Class<?> rawValueType = valueType != null ? valueType.getType() : null; Map<String, Object> sourceMap = asMap(bson); Map<Object, Object> map = CollectionFactory.createMap(mapType, rawKeyType, sourceMap.keySet().size());
/** * Root entry method into write conversion. Adds a type discriminator to the {@link Document}. Shouldn't be called for * nested conversions. * * @see org.springframework.data.mongodb.core.convert.MongoWriter#write(java.lang.Object, com.mongodb.Document) */ public void write(Object obj, Bson bson) { if (null == obj) { return; } Class<?> entityType = ClassUtils.getUserClass(obj.getClass()); TypeInformation<? extends Object> type = ClassTypeInformation.from(entityType); Object target = obj instanceof LazyLoadingProxy ? ((LazyLoadingProxy) obj).getTarget() : obj; writeInternal(target, bson, type); if (asMap(bson).containsKey("_id") && asMap(bson).get("_id") == null) { removeFromMap(bson, "_id"); } if (requiresTypeHint(entityType)) { typeMapper.writeType(type, bson); } }
Class<?> rawValueType = valueType != null ? valueType.getType() : null; Map<String, Object> sourceMap = asMap(bson); Map<Object, Object> map = CollectionFactory.createMap(mapType, rawKeyType, sourceMap.keySet().size());