How to convert Map to Bytes and save to internal storage

前端 未结 3 1582
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-20 17:09

How can I convert my Map> to byte[], and then write it to internal storage? I currently have:

        try {
                 


        
3条回答
  •  臣服心动
    2021-02-20 17:45

    I know I am subscribing to an old thread but it popped out in my google search. So I will leave my 5 cents here:

    You can use org.apache.commons.lang3.SerializationUtils which has these two methods:

    /**
     * Serialize the given object to a byte array.
     * @param object the object to serialize
     * @return an array of bytes representing the object in a portable fashion
     */
    public static byte[] serialize(Object object);
    
    /**
     * Deserialize the byte array into an object.
     * @param bytes a serialized object
     * @return the result of deserializing the bytes
     */
    public static Object deserialize(byte[] bytes);
    

提交回复
热议问题