简体   繁体   中英

How to make BlazeDS ignore properties?

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.

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM