3 Replies Latest reply on Feb 10, 2014 1:53 PM by Max Barkley

    Errai marshalling - How to mark an property non portable?

    Amit Kumar Newbie

      Hi,

       

      I have an entity named "User"(below) with a  "one to many relation" property called Address. As per the documentation marking this entity as "@Portable" will serialization the entire object tree. Is there a way to control the depth or serialization? I mean is there a way to exclude "private List<Address> addressList;" from serialization? I don't want to mark Address as @NonPortable. I just need User object for now and would load address later if i am need that information. 

       

      @Bindable

      @Portable

      @Entity

      public class User {

       

          @Id

          @GeneratedValue(strategy = GenerationType.AUTO)

          private Long id;

          

          @OneToMany(fetch=FetchType.LAZY, mappedBy="owner")

          private List<Address> addressList;

      }

       

      Thanks in advance for any suggestions.

        • 1. Re: Errai marshalling - How to mark an property non portable?
          Max Barkley Expert

          Hi Amit,

           

          If you use the "transient" keyword on a field, the marshaller will not serialize it.

           

          Cheers.

          • 2. Re: Errai marshalling - How to mark an property non portable?
            Amit Kumar Newbie

            Well,  I think in that case JPA will start ignoring it too and I don't want it. I want JPA to respect that field but marshaller to ignore it to reduce serialization process and network load. You know what i mean. 

             

            Btw, is there a any direct (static method) to get hold of "org.jboss.errai.bus.client.api.messaging.RequestDispatcher" type instance as serverside. Like ErraiBus.getDispatcher() for server side (An alternative way to Injection code like below)  :

             

            private RequestDispatcher dispatcher;

              @Inject public TuneDriveServiceImpl(RequestDispatcher dispatcher) {

              this.dispatcher = dispatcher;

              }

             

            Kind Regards

            Amit

            • 3. Re: Errai marshalling - How to mark an property non portable?
              Max Barkley Expert

              Hmm, unfortunately we don't have another way to prevent marshalling of a @Portable field. But here is a bit of work around that you could try that I think will work for you:

              • Split your current class into two classes which I will call MarshallableParent, and its subclass MarshallableChild.
              • Put all the fields you wish to transmitted over the wire in MarshallableParent.
              • Put the fields you do not wish to transmit in MarshallableChild
              • Mark MarshallableParent as @Portable
              • Mark MarshallableChild as @Portable(aliasOf = MarshallableParent.class)

               

              Now whenever you marshall the MarshallableChild class, it will use the bindings for MarshallableParent (meaning the fields only in MarshallableChild will not be transmitted).

               

              I'm less familiar with JPA so hopefully this will work with that too. As for your other question, I'm not aware of any static way to access the dispatcher or bus from server-side code.

               

              Cheers.

               

              Edit: Fixed some typos that probably made this quite confusing.