From ee23278a63b14f9481b5891e42872133ee1513c1 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Thu, 7 Mar 2024 20:55:42 +0100 Subject: [PATCH] The Buffer toJson method is being renamed to toJsonValue since toJson is actually used by data object as a convention to convert a data object to a json value. Actually toJson should return a base64 representation of the Buffer instead of parsing the content and provide an appropriate JSON value mapping. Deprecate Buffer toJson in favor of toJsonValue. --- src/main/java/io/vertx/core/buffer/Buffer.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/vertx/core/buffer/Buffer.java b/src/main/java/io/vertx/core/buffer/Buffer.java index 61497695646..ba8888167d7 100644 --- a/src/main/java/io/vertx/core/buffer/Buffer.java +++ b/src/main/java/io/vertx/core/buffer/Buffer.java @@ -136,24 +136,32 @@ static Buffer buffer(ByteBuf byteBuf) { String toString(Charset enc); /** - * Returns a Json object representation of the Buffer. + * Returns a {@link JsonObject} representation of this buffer's content. */ JsonObject toJsonObject(); /** - * Returns a Json array representation of the Buffer. + * Returns a {@link JsonArray} representation of this buffer's content. */ JsonArray toJsonArray(); /** - * Returns a Json representation of the Buffer. + * Returns a Json value representation of this buffer's content. * - * @return a JSON element which can be a {@link JsonArray}, {@link JsonObject}, {@link String}, ...etc if the buffer contains an array, object, string, ...etc + * @return a Json value which can be a {@link JsonArray}, {@link JsonObject}, {@link String}, ... if the buffer contains an array, object, string, ...etc */ - default Object toJson() { + default Object toJsonValue() { return Json.CODEC.fromBuffer(this, Object.class); } + /** + * @deprecated instead use {@link #toJsonValue()} + */ + @Deprecated + default Object toJson() { + return toJsonValue(); + } + /** * Returns the {@code byte} at position {@code pos} in the Buffer. *