-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
【安全】序列化安全能力增强,支持自定义序列化package白名单列表,提升安全性及定制性;
Showing
14 changed files
with
159 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
xxl-rpc-core/src/main/java/com/xxl/rpc/core/serializer/impl/JsonSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.xxl.rpc.core.serializer.impl; | ||
|
||
import com.alibaba.fastjson2.JSON; | ||
import com.alibaba.fastjson2.JSONReader; | ||
import com.alibaba.fastjson2.JSONWriter; | ||
import com.alibaba.fastjson2.filter.Filter; | ||
import com.xxl.rpc.core.serializer.Serializer; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* jsonb serializer | ||
* | ||
* @author xuxueli 2024-12-27 | ||
*/ | ||
public class JsonSerializer extends Serializer { | ||
|
||
/** | ||
* jsonb reader autoTypeBeforeHandler | ||
*/ | ||
private static Filter autoTypeBeforeHandler = JSONReader.autoTypeFilter("com", "org","io"); | ||
|
||
/** | ||
* allowPackageList | ||
* | ||
* @param packageList | ||
*/ | ||
@Override | ||
public void allowPackageList(List<String> packageList) { | ||
if (packageList!=null && !packageList.isEmpty()) { | ||
autoTypeBeforeHandler = JSONReader.autoTypeFilter((String[]) packageList.toArray()); | ||
} | ||
} | ||
|
||
@Override | ||
public <T> byte[] serialize(T obj) { | ||
return JSON.toJSONBytes(obj, | ||
JSONWriter.Feature.WriteClassName); | ||
} | ||
|
||
@Override | ||
public <T> Object deserialize(byte[] bytes, Class<T> clazz) { | ||
return JSON.parseObject(bytes, clazz, | ||
autoTypeBeforeHandler, | ||
JSONReader.Feature.SupportClassForName | ||
/*JSONReader.Feature.SupportAutoType*/); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.