Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VavrOptionMapper always uses ColumnMapper #2558

Closed
martyn0ff opened this issue Dec 10, 2023 · 2 comments
Closed

VavrOptionMapper always uses ColumnMapper #2558

martyn0ff opened this issue Dec 10, 2023 · 2 comments
Assignees

Comments

@martyn0ff
Copy link

I've got an issue where VavrOptionMapper is not recognizing my existing ConstructorMapper for Foo.

org.jdbi.v3.core.mapper.NoSuchMapperException: No mapper for type class com.acme.Foo nested in Option
	at org.jdbi.v3.vavr.VavrOptionMapper.lambda$map$2(VavrOptionMapper.java:54)
	at java.base/java.util.Optional.orElseThrow(Optional.java:403)
	at org.jdbi.v3.vavr.VavrOptionMapper.map(VavrOptionMapper.java:54)
	at org.jdbi.v3.vavr.VavrOptionMapper.map(VavrOptionMapper.java:30)
	at org.jdbi.v3.core.mapper.SingleColumnMapper.lambda$new$0(SingleColumnMapper.java:41)
	at org.jdbi.v3.core.mapper.SingleColumnMapper.map(SingleColumnMapper.java:55)
	at org.jdbi.v3.core.result.internal.ResultSetResultIterator.next(ResultSetResultIterator.java:83)
	at org.jdbi.v3.core.result.ResultIterable.findOne(ResultIterable.java:198)

Turns out that this mapper assumes that the mapping should always be done by the means of ColumnMapper:

final ColumnMapper<?> mapper = ctx.findColumnMapperFor(nestedType)

I believe that it should instead use a call to findMapperFor(GenericType) instead. For the time being this is easily fixable by using:

...
.mapTo(Foo.class)
.map(Option::of)
...

instead of

...
.mapTo(new GenericType<Option<Foo>>() {})
...
@hgschmie hgschmie self-assigned this Dec 22, 2023
@hgschmie
Copy link
Contributor

Hi @martyn0ff,

Thank you for filing an issue with Jdbi. This is a shortcoming of Jdbi as we do not currently have a row factory for vavr Option. This will be supported in the next release.

hgschmie added a commit to hgschmie/jdbi that referenced this issue Dec 22, 2023
Allow wrapping of arbitrary row types into vavr `Option` objects.

Addresses jdbi#2558
@hgschmie
Copy link
Contributor

hgschmie commented Jan 3, 2024

fixed in 3.43.0

@hgschmie hgschmie closed this as completed Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants