Catalin Roman
Catalin Roman

Reputation: 139

Unsupported Collection interface

I am porting a legacy application to MongoDB and therefor I'm trying to reuse the existing POJOs. I managed to succesfully persist data in MongoDB, but when I'm reading documents, it fails with the following exception:

Caused by: java.lang.IllegalArgumentException: Unsupported Collection interface: com.company.product.dto.datatypes.IObservableList
at org.springframework.core.CollectionFactory.createCollection(CollectionFactory.java:191) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readCollectionOrArray(MappingMongoConverter.java:960) ~[spring-data-mongodb-2.0.9.RELEASE.jar:2.0.9.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1385) ~[spring-data-mongodb-2.0.9.RELEASE.jar:2.0.9.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1334) ~[spring-data-mongodb-2.0.9.RELEASE.jar:2.0.9.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readProperties(MappingMongoConverter.java:335) ~[spring-data-mongodb-2.0.9.RELEASE.jar:2.0.9.RELEASE]

Is there a way solve this?

Upvotes: 1

Views: 1239

Answers (1)

David Soroko
David Soroko

Reputation: 9086

You will need to make sure that the type (collectionType) of IObservableList satisfies the logic the Spring code implements:

    if (collectionType.isInterface()) {
        if (Set.class == collectionType || Collection.class == collectionType) {
            return new LinkedHashSet<>(capacity);
        }
        else if (List.class == collectionType) {
            return new ArrayList<>(capacity);
        }
        else if (SortedSet.class == collectionType || NavigableSet.class == collectionType) {
            return new TreeSet<>();
        }
        else {
            throw new IllegalArgumentException("Unsupported Collection interface: " + collectionType.getName());
        }
    }

see https://github.com/spring-projects/spring-framework/blob/5.0.x/spring-core/src/main/java/org/springframework/core/CollectionFactory.java

Upvotes: 1

Related Questions