如何让 BlazeDS 忽略属性?

发布于 2024-10-16 22:54:24 字数 916 浏览 4 评论 0原文

我有一个java类,它有一个带有getter和setter的字段,以及第二对以另一种方式访问​​该字段的getter和setter:(

public class NullAbleId {
   private static final int NULL_ID = -1;
   private int internalId;

   getter & setter for internalId

   public  Integer getId() {
     if(this.internalId == NULL_ID) {
       return null;      
     } else {
       return Integer.valueOf(internalId);
     }
    }

    public void setId(Integer id) {
      if (id == null) {
        this.internalId = NULL_ID;
      } else {
        this.internalId = id.intValue();
      }
    }

}

这种构造的原因是我想构建一个

//stackoverflow.com/questions/4955866/best-practice-to-handle-nullable-integer-in-a-java-flex-remoting-application">在 Flash/Flex 上 客户端,我有一个具有两个属性的类:id和internalId(id属性仅用于测试,最后它们应该返回internalId值)

BlazeDS接缝传输这两个值:id和internalId,因为两者都有完整的getter二传手对。 我希望Blaze不要传输id,只应该传输internalId。但我不知道如何配置它。

I have a java class which has one field with getter and setter, and a second pair of getter and setter that access this field in another way:

public class NullAbleId {
   private static final int NULL_ID = -1;
   private int internalId;

   getter & setter for internalId

   public  Integer getId() {
     if(this.internalId == NULL_ID) {
       return null;      
     } else {
       return Integer.valueOf(internalId);
     }
    }

    public void setId(Integer id) {
      if (id == null) {
        this.internalId = NULL_ID;
      } else {
        this.internalId = id.intValue();
      }
    }

}

(the reason for this construction is that I want to build a way to hande Nullable Intergers)

On the Flash/Flex client side, I have a Class with two properties: id and internalId (the id properties are only for testing, at the end they should return the internalId value)

BlazeDS seams to transfer both values: id and internalId, because both have a complete getter setter pair. I want Blaze not to transfer id, only internalId should be transferred. But I have no idea how I have to configure that.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

染柒℉ 2024-10-23 22:54:24

BlazeDS 序列化的所有规则都在这里:

http:// livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?content=serialize_data_3.html

这里有一句话:“静态、瞬态或非公开的字段,以及非公开或非公开的 bean 属性静态的,被排除在外。”

因此,如果您可以使您的 id 属性符合该标准,它将被排除在外。另一种选择是创建一个明显不包含您的 id 属性的自定义序列化程序。

祝一切顺利,

〜哈里斯

All the rules for BlazeDS serialization are here:

http://livedocs.adobe.com/blazeds/1/blazeds_devguide/help.html?content=serialize_data_3.html

Here is a quote: "Fields that are static, transient, or nonpublic, as well as bean properties that are nonpublic or static, are excluded."

So if you can make your id property fit that criteria it will be excluded. Another option would be to create a custom serializer that overtly does not include your id property.

All the best,

~harris

故事和酒 2024-10-23 22:54:24

除了瞬态/编组器之外,您还可以实现外部化接口并创建自定义序列化。

请参阅序列化规则

Besides transient / marshaller you can implement the Externalizable interface and create your custom serialization.

See serialization rules

小矜持 2024-10-23 22:54:24

它可能有点旧,但它可以帮助一些人:有一个关于 通过 BlazeDS 排除从 Java 到 Flex 的属性

编辑:更好的解决方案,是使用 @AmfIgnore (或 @AmfIgnoreField 如果您的序列化是直接在字段上)注释存在于 spring-flex-core.jar 中(我使用了 1.5.2-RELEASE)

It maybe a little bit old, but it could help some : there is a nice ticket about excluding properties from Java to Flex via BlazeDS

EDIT : a better soluce, it's to use the @AmfIgnore (or @AmfIgnoreField if your serialization is directly on the fields) annotation present in the spring-flex-core.jar (I've used the 1.5.2-RELEASE)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文