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

    Override internal Marshaller

    Steeve Beroard Newbie

      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?





        • 1. Re: Override internal Marshaller
          Divya Dadlani Newbie

          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?



          • 2. Re: Override internal Marshaller
            Steeve Beroard Newbie

            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.





            • 3. Re: Override internal Marshaller
              Michel Werren Novice

              Hello Steve


              Can you please post the exception and your custom marshaller?




              • 4. Re: Re: Override internal Marshaller
                Steeve Beroard Newbie

                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;
                public class CustomDateMarshaller extends AbstractNullableMarshaller<Date> {
                  private DateTimeFormat format = DateTimeFormat.getFormat("yyyy-MM-dd'T'HH:mm:ssZ");
                  public Date[] getEmptyArray() {
                  return new Date[0];
                  public Date doNotNullDemarshall(EJValue o, MarshallingSession ctx) {
                  if (o.isString() != null) {
                  return format.parse(o.isString().stringValue());
                  return null;
                  public String doNotNullMarshall(Date o, MarshallingSession ctx) {
                     return "\"" + format.format(o) +"\"";


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





                • 5. Re: Override internal Marshaller
                  Randy May Newbie

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