msgpack / msgpack-java

MessagePack serializer implementation for Java / msgpack.org[Java]
http://msgpack.org/
Apache License 2.0
1.41k stars 321 forks source link

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

Open sandeepdk23 opened 1 year ago

sandeepdk23 commented 1 year ago

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 commented 1 year ago

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.