Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wennicky opened this issue Apr 23, 2018 · 1 comment
Labels

Comments

@wennicky
Copy link

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!

@komamitsu
Copy link
Member

@wennicky Are you using msgpack-java 0.6 or earlier? If so, they're already deprecated and we strongly recommend latest 0.8 although it has incompatible APIs with 0.6.

@xerial xerial added the v06 label May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants