How to make BlazeDS ignore properties?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 08:57:59

问题


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.


回答1:


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

See serialization rules




回答2:


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




回答3:


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)



来源:https://stackoverflow.com/questions/4957184/how-to-make-blazeds-ignore-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!