【问题标题】:How can I exclude a Base class from serialization process of struts json如何从struts json的序列化过程中排除基类
【发布时间】:2013-04-12 08:31:13
【问题描述】:

我可以通过以下方式将属性序列化到 Base Class (2 Levels)。

public class BaseRoot{
 String prop1; //getter and setter
}

public class SubClass extends BaseRoot{
 String prop2; //getter and setter
}

public class ActionClass extends SubClass{
 String prop3; //getter and setter
}

在 struts json 中,我可以使用

序列化所有属性
<result type="json">
 <param name="ignoreHierarchy">false</param> //This will allow parent to be serializable
 <param name="excludeProperties">price,description</param> //Exclude parameters
</result>

但我只想序列化类 ActionClass 和 SubClass。我不想序列化 BaseRoot 和其他由 BaseRoot 类扩展的类。我知道我可以排除属性。但我想从序列化中排除整个类。

【问题讨论】:

    标签: java json inheritance serialization struts2


    【解决方案1】:

    使用默认功能无法做到这一点。

    您需要编写自己的结果类型,或者可能是序列化程序,您可以将其插入现有的或新的结果类型——不确定哪个更容易。

    也就是说,我发现它的设计/需求有点粗略——也许你想要一个 Presenter、Decorator、Facade 等,而不是试图破解具体的类。

    【讨论】:

      猜你喜欢
      • 2023-04-05
      • 2012-04-27
      • 1970-01-01
      • 2012-07-19
      • 1970-01-01
      • 2011-05-14
      • 1970-01-01
      • 2012-05-15
      • 2010-12-15
      相关资源
      最近更新 更多