Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions core/src/main/java/com/alibaba/fastjson2/JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,21 @@ public byte[] toJSONBBytes(JSONWriter.Feature... features) {
}
}

/**
* Serialize to JSON UTF-8 bytes
*
* @param features features to be enabled in serialization
* @return JSON UTF-8 bytes
* @since 2.0.61
*/
public byte[] toJSONBytes(JSONWriter.Feature... features) {
try (JSONWriter writer = JSONWriter.ofUTF8(features)) {
writer.setRootObject(this);
writer.write(this);
return writer.getBytes();
}
}

/**
* Convert this {@link JSONArray} to the specified Object
*
Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/com/alibaba/fastjson2/JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,21 @@ public byte[] toJSONBBytes(JSONWriter.Feature... features) {
}
}

/**
* Serialize to JSON UTF-8 bytes
*
* @param features features to be enabled in serialization
* @return JSON UTF-8 bytes
* @since 2.0.61
*/
public byte[] toJSONBytes(JSONWriter.Feature... features) {
try (JSONWriter writer = JSONWriter.ofUTF8(features)) {
writer.setRootObject(this);
writer.write(this);
return writer.getBytes();
}
}

/**
* @since 2.0.4
*/
Expand Down
Loading