如何让 BlazeDS 忽略属性?
我有一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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
除了瞬态/编组器之外,您还可以实现外部化接口并创建自定义序列化。
请参阅序列化规则
Besides transient / marshaller you can implement the Externalizable interface and create your custom serialization.
See serialization rules
它可能有点旧,但它可以帮助一些人:有一个关于 通过 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)