Java Serializable Object to Byte Array

后端 未结 12 1312
春和景丽
春和景丽 2020-11-22 03:12

Let\'s say I have a serializable class AppMessage.

I would like to transmit it as byte[] over sockets to another machine where it is rebuil

12条回答
  •  逝去的感伤
    2020-11-22 03:46

    Another interesting method is from com.fasterxml.jackson.databind.ObjectMapper

    byte[] data = new ObjectMapper().writeValueAsBytes(JAVA_OBJECT_HERE)

    Maven Dependency

    
        com.fasterxml.jackson.core
        jackson-databind
    
    

提交回复
热议问题