Issues while deserializing exception/throwable using Jackson in Java

前端 未结 6 1798
無奈伤痛
無奈伤痛 2021-02-19 13:42

I am facing issues while deserializing Exception and Throwable instances using Jackson (version 2.2.1). Consider the following snippet:



        
6条回答
  •  暖寄归人
    2021-02-19 14:08

    Is it so necessary to use json serialization? Looks liks there are some bugs with throwables. Why not use system api:

    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(  );
    ObjectOutputStream objectOutputStream = new ObjectOutputStream( byteArrayOutputStream );
    objectOutputStream.writeObject( e );
    
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray() );
    ObjectInputStream objectInputStream = new ObjectInputStream( byteArrayInputStream );
    Throwable t = (Throwable) objectInputStream.readObject();
    

提交回复
热议问题