List of usage examples for org.springframework.data.mongodb.core.mapping MongoPersistentProperty isCollectionLike
boolean isCollectionLike();
From source file:org.springframework.data.mongodb.core.convert.MappingMongoConverter.java
@SuppressWarnings("unchecked") protected Object getValueInternal(MongoPersistentProperty prop, DBObject dbo, StandardEvaluationContext ctx, String spelExpr) {/* w w w . jav a2 s . co m*/ Object o; if (null != spelExpr) { Expression x = spelExpressionParser.parseExpression(spelExpr); o = x.getValue(ctx); } else { Object sourceValue = dbo.get(prop.getFieldName()); if (sourceValue == null) { return null; } Class<?> propertyType = prop.getType(); if (conversions.hasCustomReadTarget(sourceValue.getClass(), propertyType)) { return conversionService.convert(sourceValue, propertyType); } if (sourceValue instanceof DBRef) { sourceValue = ((DBRef) sourceValue).fetch(); } if (sourceValue instanceof DBObject) { if (prop.isMap()) { return readMap(prop.getTypeInformation(), (DBObject) sourceValue); } else if (prop.isArray() && sourceValue instanceof BasicDBObject && ((DBObject) sourceValue).keySet().size() == 0) { // It's empty return Array.newInstance(prop.getComponentType(), 0); } else if (prop.isCollectionLike() && sourceValue instanceof BasicDBList) { return readCollectionOrArray( (TypeInformation<? extends Collection<?>>) prop.getTypeInformation(), (BasicDBList) sourceValue); } TypeInformation<?> toType = typeMapper.readType((DBObject) sourceValue, prop.getTypeInformation()); // It's a complex object, have to read it in if (toType != null) { // TODO: why do we remove the type? // dbo.removeField(CUSTOM_TYPE_KEY); o = read(toType, (DBObject) sourceValue); } else { o = read(mappingContext.getPersistentEntity(prop.getTypeInformation()), (DBObject) sourceValue); } } else { o = sourceValue; } } return o; }