javamongodbmongorepositorypageable

How to fix convertion error using mongorepository with pageable


I'm getting the following error when pageable's page is 3 or higher (with values 1 or 2 it works). The error is coming from a call to mongorepository.

Failed to convert from type [java.lang.String] to type [java.lang.Boolean] for value 'string'; nested exception is java.lang.IllegalArgumentException: Invalid boolean value 'string'

The service is:

public Pagination<Foo> getList(FooQueryMap map) {
    final int size = 50;
    var pageRequest = PageRequest.of(map.getPage() - 1, size);
    
    var bar = receiptRepository
                    .getPageableOfFoo("" + map.getNumber(),pageRequest);
    
    return paginationFactory.toPaginatedResponse(bar);
}

And the repository:

public interface FooRepository extends MongoRepository<Foo, String> {

    @Query(value = "{'foo.field': ?0}")
    Page<Foo> getPageableOfFoo(String field, Pageable pageable);
}

I have no idea what is causing this problem, I suspect maybe a bug in mongo repository.


Solution

  • The error was not related to pageable or the query itself. The error was happening because junk at mongodb. There was a property on Foo that some time ago was a String and currently is a boolean, there is a record where this property was saved with the value 'String' and the mongo converter can't convert this value to boolean, and then this error is thrown.