Skip to content
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

[FEATURE]如何得到反序列化的Type #527

Closed
leonchen83 opened this issue Jul 5, 2022 · 2 comments
Closed

[FEATURE]如何得到反序列化的Type #527

leonchen83 opened this issue Jul 5, 2022 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@leonchen83
Copy link

请描述您的需求或者改进建议

对您想要需求或建议的清晰简洁的描述。

fastjson1的兼容包里return deserialze(parser, null, null);, 这里的type和fieldName都是null

public interface ObjectDeserializer
        extends ObjectReader {
    @Override
    default Object readObject(JSONReader jsonReader, long features) {
        DefaultJSONParser parser = new DefaultJSONParser(jsonReader, ParserConfig.global);
        return deserialze(parser, null, null);
    }

    <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName);

    default int getFastMatchToken() {
        return JSONLexer.UNKNOWN;
    }
}

那么在写fastjson2的反序列化器,实现ObjectReader时,如何得到typefield, 我们定制了很多自己的序列化器与反序列化器,需要这个类型信息, fastjson1可以做到取得这个类型信息, jackson 的话实现ContextualDeserializer也可以做到取得类型信息

请描述你建议的实现方案

对您想要需求或建议的实现方案的详细描述。

描述您考虑过的替代方案

对您考虑过的任何替代解决方案或功能的描述。

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@leonchen83 leonchen83 added the enhancement New feature or request label Jul 5, 2022
@wenshao wenshao added this to the 2.0.9 milestone Jul 5, 2022
@leonchen83
Copy link
Author

建议2 ,能不能做一个非static方法的JSON对象,需要做序列化器与反序列化器的不同使用方式的隔离,用JSON.register就做成全局注册了

建议3, 由于上述的原因,我们自己单独创建了JSONWriter.Context, ObjectWriterProvider, JSONWriter等对象
JSONWriter.Context里的configFilter() 是一个protected方法,我们有很多filter, 所以我们还得自己扩展将其转换成public

public class XWriterContext extends JSONWriter.Context {
	
	/**
	 * 
	 */
	public XWriterContext(ObjectWriterProvider provider) {
		super(provider);
	}
	
	public XWriterContext(ObjectWriterProvider provider, JSONWriter.Feature... features) {
		super(provider, features);
	}
	
	/**
	 * 
	 */
	@Override
	public void configFilter(Filter... filters) {
		super.configFilter(filters);
	}
}

@wenshao
Copy link
Member

wenshao commented Jul 10, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.9
问题已修复,请用新版本

@wenshao wenshao closed this as completed Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants