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
Attn: @yawkat as this deals with JsonObject, which it appears you authored in 3.1.
I have a code path in my application where I get the current thread-local Micronaut HttpRequest (from ServerRequestContext#currentRequest) and I then "readdress" and "forward" that request on to another server.
I do this by copying the (json) body from the Micronaut HttpRequest into a new java.net.http.HttpRequest and sending it to the destination URI. Here's the relevant code:
Note: this is all a bit of a hack, but it appears to be the best I can do. I might have preferred to create a mutable copy of the Micronaut HttpRequest, update its URI and then send it off with a Micronaut HttpClient, but the thread-local HttpRequest does not support the .mutate() call. That left me needing to create an all-new request.
In any case, under 3.0.3, the call above to originalRequest.getBody(String.class) returned with the JSON body of the original request, such that I could simply copy it over to the new request and send it.
On upgrading from 3.0.3 to 3.1.0-SNAPSHOT, however, this same call now returns io.micronaut.json.tree.JsonObject, which cannot as easily be passed on to the new request. How can I best get from this JsonObject back to a stringified JSON representation? Thanks.
The text was updated successfully, but these errors were encountered:
Unfortunately, the new JsonNode class can't have a json toString, because that would need a dependency on jackson-core. You can implement the toString yourself using JsonNodeTreeCodec, or after the fix go through ConversionService or JsonMapper. And of course getBody will now work as it did before.
Issue description
Attn: @yawkat as this deals with
JsonObject
, which it appears you authored in 3.1.I have a code path in my application where I get the current thread-local Micronaut
HttpRequest
(fromServerRequestContext#currentRequest
) and I then "readdress" and "forward" that request on to another server.I do this by copying the (json) body from the Micronaut
HttpRequest
into a newjava.net.http.HttpRequest
and sending it to the destination URI. Here's the relevant code:Note: this is all a bit of a hack, but it appears to be the best I can do. I might have preferred to create a mutable copy of the Micronaut
HttpRequest
, update its URI and then send it off with a MicronautHttpClient
, but the thread-localHttpRequest
does not support the.mutate()
call. That left me needing to create an all-new request.In any case, under 3.0.3, the call above to
originalRequest.getBody(String.class)
returned with the JSON body of the original request, such that I could simply copy it over to the new request and send it.On upgrading from 3.0.3 to 3.1.0-SNAPSHOT, however, this same call now returns
io.micronaut.json.tree.JsonObject
, which cannot as easily be passed on to the new request. How can I best get from thisJsonObject
back to a stringified JSON representation? Thanks.The text was updated successfully, but these errors were encountered: