This commit is contained in:
Looly 2024-09-29 01:23:44 +08:00
parent eac5024887
commit b7035dd4b4
2 changed files with 17 additions and 6 deletions

View File

@ -22,7 +22,13 @@ import org.dromara.hutool.core.util.CharsetUtil;
import java.io.*; import java.io.*;
/** /**
* JSON引擎实现 * JSON引擎接口提供API
* <ul>
* <li>serialize JSON序列化 将Bean对象序列化为JSON字符串</li>
* <li>deserializeJSON反序列化将JSON字符串解析为Bean对象</li>
* </ul>
*
* <p>{@link #init(JSONEngineConfig)}用于使用公共配置初始化引擎</p>
* *
* @author Looly * @author Looly
* @since 6.0.0 * @since 6.0.0
@ -42,8 +48,8 @@ public interface JSONEngine {
/** /**
* 生成JSON数据序列化用于将指定的Bean对象通过Writer写出为JSON字符串 * 生成JSON数据序列化用于将指定的Bean对象通过Writer写出为JSON字符串
* *
* @param bean Java BeanPOJO对象 * @param bean Java BeanPOJO对象
* @param out 写出到的{@link OutputStream} * @param out 写出到的{@link OutputStream}
*/ */
void serialize(Object bean, OutputStream out); void serialize(Object bean, OutputStream out);

View File

@ -23,7 +23,12 @@ import org.dromara.hutool.core.text.StrUtil;
import org.dromara.hutool.json.JSONException; import org.dromara.hutool.json.JSONException;
/** /**
* JSON引擎工厂 * JSON引擎工厂<br>
* 通过SPI方式动态查找用户引入的JSON实现库并加载提供两种加载方式
* <ul>
* <li>{@link #getEngine()} 自动按照service文件中的顺序检查并加载第一个可用引擎</li>
* <li>{@link #createEngine(String)} 加载指定名称的引擎</li>
* </ul>
* *
* @author looly * @author looly
* @since 6.0.0 * @since 6.0.0
@ -48,10 +53,10 @@ public class JSONEngineFactory {
*/ */
public static JSONEngine createEngine(String engineName) throws JSONException { public static JSONEngine createEngine(String engineName) throws JSONException {
// fastjson名字兼容 // fastjson名字兼容
if(StrUtil.equalsIgnoreCase("fastjson", engineName)){ if (StrUtil.equalsIgnoreCase("fastjson", engineName)) {
engineName = "FastJSON2"; engineName = "FastJSON2";
} }
if(StrUtil.equalsIgnoreCase("hutool", engineName)){ if (StrUtil.equalsIgnoreCase("hutool", engineName)) {
engineName = "HutoolJSON"; engineName = "HutoolJSON";
} }