JDBI3 SqlObject Consumer: How to fix "No Mapper Registered" error?

154 views Asked by At

What do I need to do to fix "No Mapper Registered" when trying to Stream a result set from a SqlObject DAO? The method is annotated with @RegisterBeanMapper and the documentation seems incomplete.

According to https://jdbi.org/#_consumer_arguments:

15.1.3. Consumer Arguments

As a special case, it is possible to use a Consumer argument in addition to other bound arguments.

Unless the type T is a Stream or an Iterator, the consumer is executed once for each row in the result set. The static type of parameter T determines the row type.

If the consumer implements Consumer<Iterator>, or Consumer<Stream>, then the consumer is executed once with the Iterator or Stream holding the results. The static type of parameter T determines the mapped row type here as well. When using a consumer argument with an iterator or a stream, Jdbi will manage and close them after the callback completes.

I'm using the following in a DAO interface:


    @SqlQuery(" SELECT id, title FROM " + TABLE_XML_RECORDS //
        + " WHERE" //
        + "  issuedate IS NULL" //
        + "  AND sort_date <= :issueweek" //
        + "  AND sort_date >= :oldest" //
        + "  AND sort_date IS NOT NULL" //
        + " ORDER BY sort_date DESC")
        @RegisterBeanMapper(IdTitle.class)
        void getRecordIdsFor(@Bind("issueweek") LocalDate issueweek, @Bind("oldest") LocalDate oldestSortDate, java.util.function.Consumer<Stream<IdTitle>> consumer);

But I'm getting:


    No mapper registered for type java.util.stream.Stream<clarivate.mariadb.models.IdTitle>

I've tried searching for code snippets to go by, but my search foo is failing and the documentation does not contain a simple concrete example to go by.

1

There are 1 answers

0
Michael Conrad On

Resolved by updating to the latest 3.x. It appears this is a newly added feature.

    final JDBI = '3.35.0'
    api "org.jdbi:jdbi3-core:${JDBI}"
    api "org.jdbi:jdbi3-sqlobject:${JDBI}"
    api "org.jdbi:jdbi3-stringtemplate4:${JDBI}"