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

4.x: DbClient cannot map to JSON using JSON-P #7842

Closed
romain-grecourt opened this issue Oct 19, 2023 · 0 comments
Closed

4.x: DbClient cannot map to JSON using JSON-P #7842

romain-grecourt opened this issue Oct 19, 2023 · 0 comments
Assignees
Labels
4.x Version 4.x bug Something isn't working DB client Helidon DB Client
Milestone

Comments

@romain-grecourt
Copy link
Contributor

Environment Details

  • Helidon Version: 4.0.0-RC1

Problem Description

WARNING: Internal server error
io.helidon.http.RequestException: Failed to map interface io.helidon.dbclient.DbRow to interface jakarta.json.JsonObject: Failed to map source of class 'io.helidon.dbclient.jdbc.JdbcRow'
	at io.helidon.http.RequestException$Builder.build(RequestException.java:139)
	at io.helidon.webserver.http.ErrorHandlers.unhandledError(ErrorHandlers.java:202)
	at io.helidon.webserver.http.ErrorHandlers.lambda$handleError$1(ErrorHandlers.java:182)
	at java.base/java.util.Optional.ifPresentOrElse(Optional.java:198)
	at io.helidon.webserver.http.ErrorHandlers.handleError(ErrorHandlers.java:181)
	at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:118)
	at io.helidon.webserver.http.Filters$FilterChainImpl.proceed(Filters.java:121)
	at io.helidon.webserver.observe.metrics.MetricsFeature.lambda$configureVendorMetrics$1(MetricsFeature.java:90)
	at io.helidon.webserver.http.Filters$FilterChainImpl.proceed(Filters.java:119)
	at io.helidon.webserver.http.Filters.executeFilters(Filters.java:87)
	at io.helidon.webserver.http.Filters.lambda$filter$0(Filters.java:83)
	at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:75)
	at io.helidon.webserver.http.Filters.filter(Filters.java:83)
	at io.helidon.webserver.http.HttpRouting.route(HttpRouting.java:109)
	at io.helidon.webserver.http1.Http1Connection.route(Http1Connection.java:332)
	at io.helidon.webserver.http1.Http1Connection.handle(Http1Connection.java:169)
	at io.helidon.webserver.ConnectionHandler.run(ConnectionHandler.java:155)
	at io.helidon.common.task.InterruptableTask.call(InterruptableTask.java:47)
	at io.helidon.webserver.ThreadPerTaskExecutor$ThreadBoundFuture.run(ThreadPerTaskExecutor.java:239)
	at java.base/java.lang.VirtualThread.run(VirtualThread.java:311)
Caused by: io.helidon.common.mapper.MapperException: Failed to map interface io.helidon.dbclient.DbRow to interface jakarta.json.JsonObject: Failed to map source of class 'io.helidon.dbclient.jdbc.JdbcRow'
	at io.helidon.dbclient.DbMapperManagerImpl.createMapperException(DbMapperManagerImpl.java:130)
	at io.helidon.dbclient.DbMapperManagerImpl.executeMapping(DbMapperManagerImpl.java:82)
	at io.helidon.dbclient.DbMapperManagerImpl.read(DbMapperManagerImpl.java:45)
	at io.helidon.dbclient.DbRowBase.as(DbRowBase.java:68)
	at io.helidon.examples.dbclient.pokemons.PokemonService.lambda$listPokemons$1(PokemonService.java:117)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at io.helidon.dbclient.jdbc.JdbcRow$Spliterator.tryAdvance(JdbcRow.java:100)
	at java.base/java.util.Spliterator.forEachRemaining(Spliterator.java:332)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:693)
	at io.helidon.dbclient.AutoClosingStream.collect(AutoClosingStream.java:132)
	at io.helidon.examples.dbclient.pokemons.PokemonService.listPokemons(PokemonService.java:118)
	at io.helidon.webserver.http.HttpRouting$RoutingExecutor.doRoute(HttpRouting.java:668)
	at io.helidon.webserver.http.HttpRouting$RoutingExecutor.call(HttpRouting.java:627)
	at io.helidon.webserver.http.HttpRouting$RoutingExecutor.call(HttpRouting.java:605)
	at io.helidon.webserver.http.ErrorHandlers.runWithErrorHandling(ErrorHandlers.java:75)
	... 14 more
Caused by: java.lang.ClassCastException: class io.helidon.common.mapper.ValueBacked cannot be cast to class java.lang.Integer (io.helidon.common.mapper.ValueBacked is in unnamed module of loader 'app'; java.lang.Integer is in module java.base of loader 'bootstrap')
	at io.helidon.dbclient.jsonp.JsonProcessingMapper.lambda$static$2(JsonProcessingMapper.java:47)
	at io.helidon.dbclient.jsonp.JsonProcessingMapper.toJson(JsonProcessingMapper.java:115)
	at io.helidon.dbclient.jsonp.JsonProcessingMapper.lambda$read$13(JsonProcessingMapper.java:89)
	at java.base/java.util.HashMap$Values.forEach(HashMap.java:1073)
	at io.helidon.dbclient.DbRowBase.forEach(DbRowBase.java:63)
	at io.helidon.dbclient.jsonp.JsonProcessingMapper.read(JsonProcessingMapper.java:89)
	at io.helidon.dbclient.jsonp.JsonProcessingMapper.read(JsonProcessingMapper.java:40)
	at io.helidon.dbclient.DbMapperManagerImpl.lambda$read$0(DbMapperManagerImpl.java:45)
	at io.helidon.dbclient.DbMapperManagerImpl.executeMapping(DbMapperManagerImpl.java:78)
	... 31 more

Steps to reproduce

JsonObject bookJson = dbClient.execute().namedGet("select-book", bookName)
        .map(row -> row.as(JsonObject.class))
        .orElseThrow(() -> new NotFoundException("Book not found: " + bookName));

This can be reproduced on examples/dbclient/pokemon:

curl http://localhost:51054/db/pokemon
Failed to map interface io.helidon.dbclient.DbRow to interface jakarta.json.JsonObject: Failed to map source of class 'io.helidon.dbclient.jdbc.JdbcRow'
@romain-grecourt romain-grecourt added bug Something isn't working DB client Helidon DB Client 4.x Version 4.x labels Oct 19, 2023
@romain-grecourt romain-grecourt changed the title 4.x: DbClient cannot map to Json 4.x: DbClient cannot map to Json using JSON-P Oct 19, 2023
@romain-grecourt romain-grecourt changed the title 4.x: DbClient cannot map to Json using JSON-P 4.x: DbClient cannot map to JSON using JSON-P Oct 19, 2023
romain-grecourt added a commit to romain-grecourt/helidon that referenced this issue Oct 19, 2023
- DbColumn.get() overrides Value.get() using as() instead of as().get() thus it returns an instance of Value instead of the raw value.
- Add a unit test in dbclient/jsonp

Fixes helidon-io#7842
@romain-grecourt romain-grecourt added this to the 4.0.0 milestone Oct 19, 2023
romain-grecourt added a commit that referenced this issue Oct 19, 2023
- DbColumn.get() overrides Value.get() using as() instead of as().get() thus it returns an instance of Value instead of the raw value.
- Add a unit test in dbclient/jsonp

Fixes #7842
@romain-grecourt romain-grecourt self-assigned this Oct 19, 2023
@m0mus m0mus added this to Backlog Aug 12, 2024
@m0mus m0mus moved this to Closed in Backlog Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x bug Something isn't working DB client Helidon DB Client
Projects
Archived in project
Development

No branches or pull requests

1 participant