Skip to content

Commit

Permalink
The Buffer toJson method is being renamed to toJsonValue since toJson…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
vietj committed Mar 12, 2024
1 parent 7875eba commit ee23278
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/io/vertx/core/buffer/Buffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit ee23278

Please sign in to comment.