You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importio.vertx.core.Vertximportio.vertx.core.json.JsonObjectimportio.vertx.ext.web.client.HttpRequestimportio.vertx.ext.web.client.HttpResponseimportio.vertx.ext.web.client.WebClientimportio.vertx.kotlin.coroutines.awaitResultimportio.vertx.kotlin.coroutines.dispatcherimportkotlinx.coroutines.GlobalScopeimportkotlinx.coroutines.launchfun <T> Vertx.runSuspend(block:suspendVertx.() ->T): Unit=run {
GlobalScope.launch(dispatcher()) {
block()
}
}
/** * Actually a workaround. message has non-nullable type in Kotlin.*/suspendfun <T, U> HttpRequest<T>.sendJsonAwait(obj:U) =
awaitResult<HttpResponse<T>> { sendJson(obj, it) }
/** * Actually a workaround. message has non-nullable type in Kotlin.*/suspendfun <T> HttpRequest<T>.sendJsonObjectAwait(obj:JsonObject?) =
awaitResult<HttpResponse<T>> { sendJsonObject(obj, it) }
funmain() =Vertx.vertx().runSuspend {
println(
WebClient
.create(this)
.postAbs("http://example.com/")
.sendJsonAwait(null)
.body())
println(
WebClient
.create(this)
.postAbs("http://example.com/")
.sendJsonObjectAwait(null)
.body())
}
The result of both requests is HTTP error 411 (Length Required). Looking through the relevant vertx-web code I found out that there is one point where null values passed to send* methods of HttpRequest are handled: HttpContext.handleSendRequest(). In all cases they are treated as sending a request without body. However it does not seems like a right behavior in terms on JSON. There is null value in JSON which is represented by null Java value (in terms of Jackson and io.vertx.core.json). It seems like the right thing to do here is to send a body with null characters and having content length of 4. Otherwise to do it we need external handling of jsonable null values: creating Buffer.buffer("null"), setting content type manually and calling sendBuffer.
The text was updated successfully, but these errors were encountered:
Version
Let's consider the following code:
The result of both requests is HTTP error 411 (Length Required). Looking through the relevant vertx-web code I found out that there is one point where
null
values passed tosend*
methods of HttpRequest are handled:HttpContext.handleSendRequest()
. In all cases they are treated as sending a request without body. However it does not seems like a right behavior in terms on JSON. There isnull
value in JSON which is represented bynull
Java value (in terms of Jackson andio.vertx.core.json
). It seems like the right thing to do here is to send a body withnull
characters and having content length of 4. Otherwise to do it we need external handling of jsonable null values: creatingBuffer.buffer("null")
, setting content type manually and callingsendBuffer
.The text was updated successfully, but these errors were encountered: