5 Replies Latest reply on May 27, 2016 11:00 AM by randalmay

    Override internal Marshaller

    steeveb

      Hi all,

       

      I would like to know if there is an easy way to override an internal Marshaller within Errai framework, like DateMarshaller?

      I created a custom marshaller to override DateMarshaller, and the only way I found was to prepend my class in the classpath with the same package+class name than DateMarshaller. I suppose there is a better way to do this?

       

      Thanks,

       

      Steeve

        • 1. Re: Override internal Marshaller
          ddadlani

          Hello Steeve,

           

          Have you looked at the documentation for custom marshallers? The link is http://docs.jboss.org/errai/3.1.1.Final/errai/reference/html_single/#sid-5931328_Marshalling-CustomMarshallers. Is this what you are trying to do?

           

          Cheers,
          Divya

          • 2. Re: Override internal Marshaller
            steeveb

            Hello Divya,

             

            I already had a look on the documentation, and I created a CustomMarshaller in that way. The problem I got is that there was an exception because I was trying to remap java.util.Date serialization. So I used my workaround to make it work, and I was just wondering if there was a builtin way to do this as I didn't find this in the documentation.

             

            Regards,

             

            Steeve

            • 3. Re: Override internal Marshaller
              werrenmi

              Hello Steve

               

              Can you please post the exception and your custom marshaller?

               

              Regards

              Michel

              • 4. Re: Re: Override internal Marshaller
                steeveb

                Hi Michel,

                 

                Here is the exception I got:

                java.lang.IllegalStateException: Mapping definition collision for java.util.Date

                [ERROR] Already have: MappingDefinition [mappingClass=java.util.Date, clientMarshallerClass=class org.jboss.errai.marshalling.client.marshallers.CustomDateMarshaller, serverMarshallerClass=null]

                [ERROR] Attempted to add: MappingDefinition [mappingClass=java.util.Date, clientMarshallerClass=class org.jboss.errai.marshalling.client.marshallers.DateMarshaller, serverMarshallerClass=null]

                And the class I created

                package org.jboss.errai.marshalling.client.marshallers;
                
                
                import java.util.Date;
                
                
                import org.jboss.errai.marshalling.client.api.MarshallingSession;
                import org.jboss.errai.marshalling.client.api.annotations.ClientMarshaller;
                import org.jboss.errai.marshalling.client.api.annotations.ServerMarshaller;
                import org.jboss.errai.marshalling.client.api.json.EJValue;
                import org.jboss.errai.marshalling.client.marshallers.AbstractNullableMarshaller;
                
                
                import com.google.gwt.i18n.client.DateTimeFormat;
                
                
                @ServerMarshaller(Date.class)
                @ClientMarshaller(Date.class)
                public class CustomDateMarshaller extends AbstractNullableMarshaller<Date> {
                
                
                  private DateTimeFormat format = DateTimeFormat.getFormat("yyyy-MM-dd'T'HH:mm:ssZ");
                
                
                  @Override
                  public Date[] getEmptyArray() {
                  return new Date[0];
                  }
                
                
                  @Override
                  public Date doNotNullDemarshall(EJValue o, MarshallingSession ctx) {
                  if (o.isString() != null) {
                  return format.parse(o.isString().stringValue());
                  }
                  return null;
                  }
                
                
                  @Override
                  public String doNotNullMarshall(Date o, MarshallingSession ctx) {
                     return "\"" + format.format(o) +"\"";
                  }
                
                
                }
                

                 

                I would like to replace the internal DateMarshaller by my implementation.

                 

                Regards,

                 

                Steeve

                • 5. Re: Override internal Marshaller
                  randalmay

                  Were you able to override the default marshaller?  I am trying to override the default Object Marshaller, so I am very interested in this.