Skip to content

Got "java.lang.String cannot be cast to [B" when using messagePack.read(); #474

Open
@wennicky

Description

@wennicky

Hi,

I use messagePack.write(myCalss) and stored it to Redis.
Then I opened a terminal and by using Redis command "hget" I got a what I just stored in Redis. This is what I've got:
"\xac\xed\x00\x05ur\x00\x02[B\xac\xf3\x17\xf8\x06\bT\xe0\x02\x00\x00xp\x00\x00\x00A\x98\xaa8621161813\x00\xda\x00,mKHuEReeu7RYSxcdWFRMd+IE7FaskrViwxXdMdCUEKQ=\xc0\xc0\xc0\x00\x00"
Now I want to deserialization this by messagePack.read() to convert this to MyClass. This is my codes:

Object o = "\xac\xed\x00\x05ur\x00\x02[B\xac\xf3\x17\xf8\x06\bT\xe0\x02\x00\x00xp\x00\x00\x00A\x98\xaa8621161813\x00\xda\x00,mKHuEReeu7RYSxcdWFRMd+IE7FaskrViwxXdMdCUEKQ=\xc0\xc0\xc0\x00\x00";
MessagePack messagePack = new MessagePack();
MyClass myClass= messagePack.read((byte[]) o, MyClass.class);
System.out.println(myClass.toString());

Then I got an exception on this line " MyClass myClass= messagePack.read((byte[]) o, MyClass.class);". It said "java.lang.ClassCastException: java.lang.String cannot be cast to [B"

I copied the string "\xac...\x00" from the terminal because I have to write the query in Redis and convert this string to MyClass in codes.

Can anyone help me? Thank you so much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions