Hesse deserialize java.lang.Character as string

I've been using Hessian for a while but only noticed the following behavior. If you serialize java.lang.Character to Hessian, it is deserialized as a string.

public class TestHessianChar {
    public static void main(String... args) throws IOException {
        // Serialize
        Character c = new Character('x');
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        Hessian2Output hessian2Output = new Hessian2Output( byteArrayOutputStream );
        hessian2Output.startMessage();
        hessian2Output.writeObject(c);
        hessian2Output.completeMessage();
        hessian2Output.close();
        byte[] dataBytes = byteArrayOutputStream.toByteArray();

        // Deserialize
        Hessian2Input hessian2Input = new Hessian2Input( new ByteArrayInputStream(  dataBytes ) );
        hessian2Input.startMessage();
        Object o = hessian2Input.readObject();
        hessian2Input.completeMessage();
        hessian2Input.close();

        System.out.println(o.getClass().getName());
    }
}

      

The output for this code is:

java.lang.String

      

I'm guessing it has something to do with language independent serialization of primitives, but this is pretty annoying. I am writing a JMS driver and have to differentiate between char and String as the spec requires different behavior. I'm thinking about writing my own class to represent the char (and give up auto-boxing), but I wanted to know if there was a way to get Gessian to treat the character as a character before I start going through such distortions.

+3


source to share





All Articles