具有仿制药和侵害的gson审判
我有以下课程:
public class AdminCommand<O extends AdminCommandType, P> {
O type;
P payload;
public AdminCommand() {
}
public AdminCommand(O type, P payload) {
this.type = type;
this.payload = payload;
}
}
我能够正确地序列化并进行序列化。
但是,我需要做子课,所以我要做以下操作:
public class AdminCommand<O extends AdminCommandType, P> {
O type;
P payload;
public AdminCommand() {
}
public AdminCommand(O type, P payload) {
this.type = type;
this.payload = payload;
}
}
public interface AdminCommandType {}
我在第一堂课中将枚举带入了界面。
当我对此课程进行挑选时,我会遇到问题。我尝试使用具有以下定义的类型令牌:
new TypeToken<TestCommand<<Enum which implements the interface>, <Regular POJO>>(){}.getType();
但是,当我尝试进行挑选时,我会得到2个不同的错误:
- 被铸成一个字符串
- 。
枚举
I have the following class:
public class AdminCommand<O extends AdminCommandType, P> {
O type;
P payload;
public AdminCommand() {
}
public AdminCommand(O type, P payload) {
this.type = type;
this.payload = payload;
}
}
I am able to serialize and deserialize it properly.
However, I need to make child classes, so I do the following:
public class AdminCommand<O extends AdminCommandType, P> {
O type;
P payload;
public AdminCommand() {
}
public AdminCommand(O type, P payload) {
this.type = type;
this.payload = payload;
}
}
public interface AdminCommandType {}
I have taken the enum in the first class and converted it to an interface.
I am running into problems when I deserialize this class. I tried to use a type token with the following definition:
new TypeToken<TestCommand<<Enum which implements the interface>, <Regular POJO>>(){}.getType();
However, when I try to deserialize, I get 2 different errors:
- The Enum gets cast to a String
- The POJO deserializes into a TreeMap
Is there a way to I can deserialize this class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论