具有仿制药和侵害的gson审判

发布于 2025-01-21 14:55:12 字数 890 浏览 1 评论 0原文

我有以下课程:

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个不同的错误:

  1. 被铸成一个字符串

枚举

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:

  1. The Enum gets cast to a String
  2. The POJO deserializes into a TreeMap

Is there a way to I can deserialize this class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文