Search in sources :

Example 1 with Alias

use of org.springframework.data.mapping.Alias in project spring-data-mongodb by spring-projects.

the class DefaultMongoTypeMapper method writeTypeRestrictions.

/*
	 * (non-Javadoc)
	 * @see org.springframework.data.mongodb.core.convert.MongoTypeMapper#writeTypeRestrictions(java.util.Set)
	 */
@Override
public void writeTypeRestrictions(Document result, @Nullable Set<Class<?>> restrictedTypes) {
    if (ObjectUtils.isEmpty(restrictedTypes)) {
        return;
    }
    BasicDBList restrictedMappedTypes = new BasicDBList();
    for (Class<?> restrictedType : restrictedTypes) {
        Alias typeAlias = getAliasFor(ClassTypeInformation.from(restrictedType));
        if (!ObjectUtils.nullSafeEquals(Alias.NONE, typeAlias) && typeAlias.isPresent()) {
            restrictedMappedTypes.add(typeAlias.getValue());
        }
    }
    accessor.writeTypeTo(result, new Document("$in", restrictedMappedTypes));
}
Also used : BasicDBList(com.mongodb.BasicDBList) Alias(org.springframework.data.mapping.Alias) Document(org.bson.Document)

Aggregations

BasicDBList (com.mongodb.BasicDBList)1 Document (org.bson.Document)1 Alias (org.springframework.data.mapping.Alias)1