-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
提供Redisson的Codec #2420
Labels
Milestone
Comments
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2-extension/2.0.49-SNAPSHOT/
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension</artifactId>
<version>2.0.49-SNAPSHOT</version>
</dependency>
@Test
public void json() throws Exception {
JSONCodec codec = new JSONCodec(Bean.class);
Bean bean = new Bean();
bean.name = "abc";
ByteBuf encoded = codec.getValueEncoder()
.encode(bean);
Bean decoded = (Bean) codec.getValueDecoder().decode(encoded, null);
assertEquals(bean.name, decoded.name);
}
@Test
public void jsonAutoType() throws Exception {
JSONCodec codec = new JSONCodec(
JSONFactory.createWriteContext(JSONWriter.Feature.WriteClassName),
JSONFactory.createReadContext(JSONReader.autoTypeFilter(Bean.class))
);
Bean bean = new Bean();
bean.name = "abc";
ByteBuf encoded = codec.getValueEncoder()
.encode(bean);
Bean decoded = (Bean) codec.getValueDecoder().decode(encoded, null);
assertEquals(bean.name, decoded.name);
}
@Test
public void jsonb() throws Exception {
JSONBCodec codec = new JSONBCodec(Bean.class);
Bean bean = new Bean();
bean.name = "abc";
ByteBuf encoded = codec.getValueEncoder()
.encode(bean);
Bean decoded = (Bean) codec.getValueDecoder().decode(encoded, null);
assertEquals(bean.name, decoded.name);
}
@Test
public void jsonbAutoType() throws Exception {
JSONBCodec codec = new JSONBCodec(
JSONFactory.createWriteContext(JSONWriter.Feature.WriteClassName),
JSONFactory.createReadContext(JSONReader.autoTypeFilter(Bean.class))
);
Bean bean = new Bean();
bean.name = "abc";
ByteBuf encoded = codec.getValueEncoder()
.encode(bean);
Bean decoded = (Bean) codec.getValueDecoder()
.decode(encoded, null);
assertEquals(bean.name, decoded.name);
}
public static class Bean {
public String name;
} 其中autoType的例子,为了避免自动类型带来的安全问题,手动配置JSONReader.autoTypeFilter是配置自动类型支持的类名前缀,参考 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
请描述您的需求或者改进建议
对比过几大顶流序列化框架,FastJson的JSONB性能非常优异,想在redisson中使用FastJson的JSONB作为Codec
请描述你建议的实现方案
实现Redisson的接口Codec
![image](https://private-user-images.githubusercontent.com/4993939/320894136-88083ff0-11d5-43c8-8afe-07b86feae3b5.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1NzU0NTQsIm5iZiI6MTczOTU3NTE1NCwicGF0aCI6Ii80OTkzOTM5LzMyMDg5NDEzNi04ODA4M2ZmMC0xMWQ1LTQzYzgtOGFmZS0wN2I4NmZlYWUzYjUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTRUMjMxOTE0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NWIzNmQ4OWYxYzRlYWQxNTQzNTMyZGE5ZDg5NmZmOWZhMjU4YWVhZWUzNzJhOTgzOGJhZjJhNmJlZTExZjMzYyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.moQjGCvtbLQiXGdKYejeYz-vpVl2x__HKOzu16rmF4w)
描述您考虑过的替代方案
除了自己实现Codec,也可以和Redisson的开发人员沟通,让Redisson实现FastJson版的Redisson的Codec
附加信息
暂无
The text was updated successfully, but these errors were encountered: