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

Cannot unpack/read data in Java which is packed and stored in Redis using MS.NET #721

Open
sandeepdk23 opened this issue Mar 20, 2023 · 1 comment

Comments

@sandeepdk23
Copy link

We have code implemented in MS.NET that uses .NET version of MessagePack library to serialize .NET class object into
bytes and then stores these bytes into Redis Cache.

Code in MS.NET to generate bytes which gets stored into Redis is -

public byte[] SerializeCompact(T thisObj)
{
var serializer = MessagePackSerializer.Get();
using(var byteStream = new MemoryStream())
{
serializer.pack(byteStream, thisObj);
return byteStream.ToArray();
}
}

I need to read these bytes and then deserialize it into JAVA Object (POJO).
I have added spring-boot-starter-data-redis, msgpack-core (0.9.3) & jackson-dataformat-msgpack(0.9.3) dependencies in the pom file.
I have defined connectionFactory and redisTemplate beans.
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String,Object>();

And I have disabled default serializers.

Given that the data get stored as byte[] from the above given .NET code, I am fetching the value from redis as below -

byte[] responseBytes = (byte[])redisTemplate.opsForValue().get("my_key")

First of all the response bytes that I get in above mentioned JAVA code are different than the bytes that I get when I do similar operation from my MS.NET code. Not sure if this is somehow impacting the conversion/deseralization

Then I am doing standard ObjectMapper operation on the returned responseBytes... something like below -

ObjectMapper objectMapper = new MessagePackMapper();
Account account = objectMapper.readValue(responseBytes, Account.class);

Though this line of code does not throw any error, it does not set the object value either.

Point to note, when the object is stored into Redis, it only stores values of the properties and not like json or in typical key-value format.

How do you suggest I can move ahead in order to read the value and convert it into POJO?

Thanks

@komamitsu
Copy link
Member

Sorry for the delayed response.

The issue you reported was related to Redis cache and MS.NET version MessagePack, so I can't reproduce and look into it. Could you share a minimum code to reproduce the issue? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants