3 Replies Latest reply on Mar 25, 2013 11:17 AM by Jonathan Fuerth

    Default Marshaller having problems with UTF-8 encoding

    Jörn Tysper Newbie

      Hi guys,


      we are having problems with UTF-8 encoding in the marshaller.

      All special characters that are sent to the client appear to have been converted from UTF-8 to ASCII and back.


      We're using Errai 2.2.0.Final with the StandardAsyncServlet on a WebSphere Application Server.


      I debugged through the server-side code and it appears that the marshaller-chain itself causes the problem.


      The class org.jboss.errai.marshalling.server.marshallers.DefaultDefinitionMarshaller implements the following method:



        public String marshall(final Object o, final MarshallingSession ctx) {

          final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(1024);

          try {

            marshall(byteArrayOutputStream, o, ctx);

            return new String(byteArrayOutputStream.toByteArray());


          catch (Exception e) {

            throw new RuntimeException(e);




      It gives a ByteArrayOutputStream to the method marshall(final OutputStream outstream, final Object o, final MarshallingSession mSession) which adds UTF-8 encoded bytes to the stream.

      These are given to the standard-constructor of String, which uses the systems default charset and defaults to Latin1 if none is set.


      Is there a good reason for not directly using new String(byteArrayOutputStream.toByteArray(), "UTF-8"))?

      Which other possible character set other than UTF-8 could make sense here? The marshalled String has been converted to bytes using UTF-8 after all..


      In order to solve the problem locally I had to set the global character encoding of my local application server to UTF-8 via JVM args (something our operations team surely wouldn't like on integration or production).