Mapping a Row object to a class or JSON response
Closed this issue · 11 comments
Hi there,
I'm sorry if I'm asking a stupid question but I was wondering what's the best way to retrieve the Cassandra data and map it to an object or JSON response?
With the Datastax driver it's recommended to use a mapper but i did not find a way to use the mapper here because the Cassandra session is closed off.
The other solution would be to create a customer handler that loops over the rows and transforms it to responses and/or POJO's.
Example code:
database.executeWithFullFetch(query) { fetch ->
if (fetch.succeeded()) {
val rows = fetch.result()
event.response().end() // best way to map it to a response?
} else {
println("Unable to execute the query")
fetch.cause().printStackTrace()
}
}
I would appreciate the help.
With the Datastax driver it's recommended to use a mapper but i did not find a way to use the mapper here because the Cassandra session is closed off.
Yes, for now, there is no way. But, even if we would expose the Session object you would be able to do save/get/delete operations in non-Vert.x way(with ListenableFuture), which is not good.
As a solution, I think we can implement a wrapper around MappingManager and Mapper, so a user will be able to use result mapping and save/get/delete operations(which will return io.vertx.core.Future).
Sure thing, I’d be happy to help.
Good. Look forward to your PR. If you have any questions, feel free to ask them.
@Sammers21 @zwennesm implementing a vertxy mapping manager sounds good to me. However it shouldn't be done with Future
, but rather with a Handler<AsyncResult>
. Then codegen will be able to process the methods and generate the rxified API.
However it shouldn't be done with Future, but rather with a Handler.
agree with this
Thanks @Sammers21 and @tsegismont for the instructions and information. I'll give it a start somewhere in the upcoming days. One small question upfront though. Would you like the mapper to be integrated into the vertx-cassandra-client
, or shall I make it as a separate dependency so that users can decide whether to include it or not (such as this: https://github.com/ef-labs/vertx-cassandra).
I believe having a single project is better.
+1
Fixed in #20