eclipse-vertx / vertx-http-proxy

vertx http proxy
Eclipse Public License 2.0
55 stars 36 forks source link

Add body interceptor #81

Closed wzy1935 closed 4 months ago

wzy1935 commented 5 months ago

Related to issue 65. It adds a body interceptor to transform body (also in json format).

(Draft only, there's a potential bug that makes the test stuck)

wzy1935 commented 5 months ago

The test will fail for now cause there are errors in using Json.encodeToBuffer and Json.decodeValue. But I think that might be my version problem? Here's an example for reproduce:

JsonObject o = Json.decodeValue("{\"k2\":2}", JsonObject.class);

Gives:

Exception in thread "main" io.vertx.core.json.DecodeException: Failed to decode
    at io.vertx.core.json.jackson.JacksonCodec.cast(JacksonCodec.java:418)
    at io.vertx.core.json.jackson.JacksonCodec.fromParser(JacksonCodec.java:210)
    at io.vertx.core.json.jackson.JacksonCodec.fromString(JacksonCodec.java:85)
    at io.vertx.core.json.Json.decodeValue(Json.java:83)
    at Scratch.main(Scratch.java:48)
tsegismont commented 5 months ago

The Javadoc of io.vertx.core.json.Json#decodeValue(java.lang.String, java.lang.Class<T>) reads Decode a given JSON string to a POJO of the given class type.

You can't use this method to decode a payload to Vert.x JsonObject. If you know the type the payload, use new JsonObject(str). If you don't use Json.decodeValue(str).

tsegismont commented 4 months ago

Can you rebase your PR and solve the conflicts please?

wzy1935 commented 4 months ago

Updated, thank you! (tried a couple of times for rebase, sorry for the delay)