Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

关于【接口】有【多个实现类】的时候,我无法使用 @JSONField 等去手动指定默认实现时,我如何自定义 serialize/deserialize 过程 / 记录实现类信息+反序列化回来? #4406

Open
SolarisNeko opened this issue Jun 2, 2023 · 0 comments

Comments

@SolarisNeko
Copy link

Question

1、 问题

抽象问题:一个接口,n个实现,序列化不会保留相关信息,反序列化的时候遇到接口报错。

List 的问题

2、举例

假设有个

public interface Action {  
void print();
 }

他旗下有n个实现类。如:ActionA, ActionB ... ActionAA extends ActionA

同时,我的 Root Class 是一个 class Student,他持有 List actionList;

我如何实现【序列化】的时候,对 Student.actionList,序列他的【全限定类名】?
并在【反序列化】的时候,进行构造回来?

我在 fastjson2 没找到对应的 SerializeConfig,是用 Filter 去做吗?

@SolarisNeko SolarisNeko changed the title 关于【接口】多个实现类的时候,我无法使用 @JSONField 等去手动指定,且有大量这样的数据结构,我如何自定义 serialize/deserialize 过程 / 记录实现类信息+反序列化回来? 关于【接口】有【多个实现类】的时候,我无法使用 @JSONField 等去手动指定默认实现时,我如何自定义 serialize/deserialize 过程 / 记录实现类信息+反序列化回来? Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant