We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
不可变集合反序列化异常
请填写以下信息:
模型:
@Data @Schema(description = "登录用户信息") public class LoginUser implements Serializable { private static final long serialVersionUID = 1462777779589266417L; @Schema(title = "登录名") private String name; @Schema(title = "真实名称") private String realName; @Schema(title = "所属组织ID") private Long orgId; @Schema(title = "用户权限角色列表") private Set<Long> authorities; /** * 设置权限角色列表 * * @param authorities 权限角色集合 */ public void setAuthorities(Set<Long> authorities) { if (ObjectUtil.isEmpty(authorities)) { return; } this.authorities = Collections.unmodifiableSet(authorities); } }
测试方法:
public static void main(String[] args) { JSON.mixIn(LoginUser.class, LoginUserMixin.class); LoginUser loginUser = new LoginUser(); loginUser.setName("张三"); loginUser.setRealName("zhangsan"); loginUser.setAuthorities(CollUtil.newHashSet(1L, 2L)); byte[] asd = JSONB.toBytes(loginUser, JSONWriter.Feature.WriteClassName, JSONWriter.Feature.FieldBased, JSONWriter.Feature.ErrorOnNoneSerializable, JSONWriter.Feature.ReferenceDetection, JSONWriter.Feature.WriteNulls, JSONWriter.Feature.NotWriteDefaultValue, JSONWriter.Feature.NotWriteHashMapArrayListClassName, JSONWriter.Feature.WriteNameAsSymbol); ContextAutoTypeBeforeHandler contextAutoTypeBeforeHandler = new ContextAutoTypeBeforeHandler("java.util.Collections$UnmodifiableSet", "com.kt.data.base.models.app.LoginUser"); LoginUser as = JSONB.parseObject(asd, LoginUser.class, contextAutoTypeBeforeHandler, JSONReader.Feature.UseDefaultConstructorAsPossible, JSONReader.Feature.ErrorOnNoneSerializable, JSONReader.Feature.IgnoreAutoTypeNotMatch, JSONReader.Feature.UseNativeObject, JSONReader.Feature.FieldBased); System.out.println("aaa"); }
尝试过使用mixin为属性独立设置反序列化方法,无效 反序列化类
public class LoginUserFastJsonDeserializer implements ObjectReader<Set<Long>> { @Override public Set<Long> readObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) { if (jsonReader.isNull()) { return null; } if (jsonReader.nextIfNull()) { return null; } for (; ; ) { if (jsonReader.nextIfObjectEnd()) { break; } String field = jsonReader.readFieldName(); if (ObjectUtil.isEmpty(field)) { continue; } String aa = jsonReader.readString(); System.out.println(""); } return null; } @Override public Set<Long> readJSONBObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) { return readObject(jsonReader, fieldType, fieldName, features); } }
mixin类
public abstract class LoginUserMixin { @JSONField(deserializeUsing = LoginUserFastJsonDeserializer.class) private Set<Long> authorities; }
目前是设置到字段上上反序列化无效,根本不进方法;设置到类上有效果但是没有反序列化对象的demo不知道该怎么做
正常序列化LoginUser对象中authorities属性
dubbo3.2.1开始使用fastjson2,重升级后开始出现该问题,测试方法摘自FastJson2Serialization
The text was updated successfully, but these errors were encountered:
fix deserialize unmodifiableSet, for issue #1509
add5b5e
https://github.com/alibaba/fastjson2/releases/tag/2.0.33 请用新版本
Sorry, something went wrong.
No branches or pull requests
问题描述
不可变集合反序列化异常
环境信息
请填写以下信息:
重现步骤
模型:
测试方法:
尝试过使用mixin为属性独立设置反序列化方法,无效
反序列化类
mixin类
目前是设置到字段上上反序列化无效,根本不进方法;设置到类上有效果但是没有反序列化对象的demo不知道该怎么做
期待的正确结果
正常序列化LoginUser对象中authorities属性
相关日志输出
附加信息
dubbo3.2.1开始使用fastjson2,重升级后开始出现该问题,测试方法摘自FastJson2Serialization
The text was updated successfully, but these errors were encountered: