Got String instead of the desired Pojo Type I need after deserialization

41 views
Skip to first unread message

Tsin Yi

unread,
Feb 18, 2019, 4:21:53 AM2/18/19
to protostuff


       @David Yu:

           When I tried to deserialize bytes from Redis(the Serializer works just fine), I got String instead of the desired Pojo Type I need after deserialization, the following is my custom serializer(implements RedisSerializer) :

          (And by the way ,how to allocate a proper size of the LinkedBuffer)


1550481232145.jpg

      Much Thanks!

    


David Yu

unread,
Feb 18, 2019, 4:31:05 AM2/18/19
to protostuff
On Mon, Feb 18, 2019 at 5:21 PM Tsin Yi <light...@gmail.com> wrote:


       @David Yu:

           When I tried to deserialize bytes from Redis(the Serializer works just fine), I got String instead of the desired Pojo Type I need after deserialization, the following is my custom serializer(implements RedisSerializer) :
Can you provide a simple example that I can replicate? 

          (And by the way ,how to allocate a proper size of the LinkedBuffer)
If multiple threads are accessing that method concurrently, your instance field "buffer" will cause problems.
So what you would do is use ThreadLocal to store a reference and use that.

    /**
     * Local serialization buffer for each thread 
     */
 
    static final ThreadLocal<LinkedBuffer> LOCAL_BUFFER = new ThreadLocal<LinkedBuffer>() { 
        @Override 
        protected LinkedBuffer initialValue() { 
            return LinkedBuffer.allocate(8192); 
        } 
    }; 

// usage
LinkedBuffer lb = LOCAL_BUFFER.get();


1550481232145.jpg

      Much Thanks!

    


--
You received this message because you are subscribed to the Google Groups "protostuff" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protostuff+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
When the cat is away, the mouse is alone.
dyuproject.com
Reply all
Reply to author
Forward
0 new messages