Search code examples
spring-data

Does Spring Data have provision for registering other collection and option/maybe types as return types of repository methods?


Spring Data has provision for various non-JDK types to be returned by repository methods, for example, a Vavr Seq from a multiple-result query and a Vavr Option from a single-result query. Does Spring Data have provision for me to register other collection and option/maybe types?


Solution

  • Yes, the already exsiting support for Vavr and Eclipse Collections is open for extension. All you need to do is provide an implementation of org.springframework.data.util.CustomCollectionRegistrar and register it in META/INF/spring.factories:

    org.springframework.data.util.CustomCollectionRegistrar=com.acme.YourImplementation
    

    Existing implementations can be found in:

    • Vavr – org.springframework.data.util.CustomCollections.VavrCollections
    • Eclipse Collections – org.springframework.data.util.CustomCollections.EclipseCollections