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
简要描述您碰到的问题。
反序列化出来的结构是错误的。
请填写以下信息:
package com.alibaba.fastjson2.issues_2300; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONReader; import com.alibaba.fastjson2.JSONWriter; import com.alibaba.fastjson2.filter.Filter; import lombok.Data; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.jupiter.api.Assertions; import java.io.Serializable; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class Issue230x { @Data public static final class AttributeKey<T extends Serializable> implements Serializable { private static final long serialVersionUID = 1L; private final String name; public AttributeKey(final String name) { this.name = name; } } @Data @Slf4j public static final class PubSubAttributes implements Serializable { private static final long serialVersionUID = 1L; private final Map<AttributeKey<?>, Serializable> attributes; public PubSubAttributes() { this(new ConcurrentHashMap<>()); } PubSubAttributes(Map<AttributeKey<?>, Serializable> attributes) { this.attributes = attributes; } public <T extends Serializable> T setAttribute( final @NonNull AttributeKey<T> attributeKey, final @NonNull T value) { return (T) attributes.put(attributeKey, value); } public <T extends Serializable> T getAttribute(final @NonNull AttributeKey<T> attributeKey) { return (T) attributes.get(attributeKey); } } @Data public static final class Subscription { private PubSubAttributes attributes; } @Test @SuppressWarnings("deprecated") public void testWriteClassName() { final Filter filter = JSONReader.autoTypeFilter( true, "com.alibaba.fastjson2.", "java."); final PubSubAttributes attributes = new PubSubAttributes(); final AttributeKey<String> APP_KEY = new AttributeKey<>("appKey"); attributes.setAttribute(APP_KEY, "123456"); // final Subscription subscription = new Subscription(); subscription.setAttributes(attributes); final String jsonStr = JSON.toJSONString(subscription, JSONWriter.Feature.WriteClassName); //works //final Subscription parsedSubscription = JSON.parseObject(jsonStr, Subscription.class, SupportAutoType); //does not work final Subscription parsedSubscription = JSON.parseObject(jsonStr, Subscription.class, filter); Assertions.assertEquals("123456", parsedSubscription.getAttributes().getAttribute(APP_KEY)); } }
对您期望发生的结果进行清晰简洁的描述。
单元测试通过
org.opentest4j.AssertionFailedError: expected: <123456> but was: <null> 预期:123456 实际:null
如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。
The text was updated successfully, but these errors were encountered:
AttributeKey这个类需要交给autoTypeFilter
Sorry, something went wrong.
另外就是autoTypeFilter不是需要全类名吗 ,我没有像你这么用过 不确定
全名也不行的,我把几个类都全名了也不行。
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.49-SNAPSHOT/ 问题已经修复,请帮忙用2.0.49-SNAPSHOT版本验证,2.0.49版本预计在4月底发布
Map support autoTypeFilter, for issue #2367
4e1e92c
https://github.com/alibaba/fastjson2/releases/tag/2.0.49 问题已修复,请用新版本
No branches or pull requests
问题描述
简要描述您碰到的问题。
反序列化出来的结构是错误的。
环境信息
请填写以下信息:
重现步骤
期待的正确结果
对您期望发生的结果进行清晰简洁的描述。
单元测试通过
相关日志输出
附加信息
如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。
The text was updated successfully, but these errors were encountered: