test: 新增 json 序列化插件的单元测试

This commit is contained in:
click33
2025-03-21 00:47:55 +08:00
parent 9058e7edc4
commit 35cbd38b3b
9 changed files with 399 additions and 1 deletions

View File

@@ -15,6 +15,7 @@
*/
package cn.dev33.satoken.json;
import cn.dev33.satoken.util.SaFoxUtil;
import com.alibaba.fastjson.JSON;
/**
@@ -30,6 +31,9 @@ public class SaJsonTemplateForFastjson implements SaJsonTemplate {
*/
@Override
public String objectToJson(Object obj) {
if(SaFoxUtil.isEmpty(obj)) {
return null;
}
return JSON.toJSONString(obj);
}
@@ -38,6 +42,9 @@ public class SaJsonTemplateForFastjson implements SaJsonTemplate {
*/
@Override
public<T> T jsonToObject(String jsonStr, Class<T> type) {
if(SaFoxUtil.isEmpty(jsonStr)) {
return null;
}
return JSON.parseObject(jsonStr, type);
}