Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public static byte[] encode(final Object obj) {
if (obj == null) {
return null;
}
final String json = toJson(obj, false);
return json.getBytes(CHARSET_UTF8);
return JSON.toJSONBytes(obj, CHARSET_UTF8);
}

public static String toJson(final Object obj, boolean prettyFormat) {
Expand All @@ -45,31 +44,22 @@ public static <T> T decode(final byte[] data, Class<T> classOfT) {
if (data == null) {
return null;
}
return fromJson(data, classOfT);
return JSON.parseObject(data, classOfT);
}

public static <T> List<T> decodeList(final byte[] data, Class<T> classOfT) {
if (data == null) {
return null;
}
String json = new String(data, CHARSET_UTF8);
return JSON.parseArray(json, classOfT);
return JSON.parseArray(data, 0, data.length, CHARSET_UTF8, classOfT);
}

public static <T> T fromJson(String json, Class<T> classOfT) {
return JSON.parseObject(json, classOfT);
}

private static <T> T fromJson(byte[] data, Class<T> classOfT) {
return JSON.parseObject(data, classOfT);
}

public byte[] encode() {
final String json = this.toJson();
if (json != null) {
return json.getBytes(CHARSET_UTF8);
}
return null;
return JSON.toJSONBytes(this, CHARSET_UTF8);
}

/**
Expand All @@ -79,8 +69,7 @@ public byte[] encode() {
* @return serialized data.
*/
public byte[] encode(JSONWriter.Feature... features) {
final String json = JSON.toJSONString(this, features);
return json.getBytes(CHARSET_UTF8);
return JSON.toJSONBytes(this, CHARSET_UTF8, features);
}

public String toJson() {
Expand All @@ -90,4 +79,4 @@ public String toJson() {
public String toJson(final boolean prettyFormat) {
return toJson(this, prettyFormat);
}
}
}
Loading