Search code examples
javajsonosgiserializable

How do I put Serializable Objects in a JSON body? In what format should I store in my database?


I am building a logging/journal service for an osgi framework, with the intention of using my journal entries for restoring the system from a backup after a systemfailure. But I came across a problem: to make sure I have enough data, necessary to be able to restore the system correctly, I need to pass used functioncalls and their arguments.

I pass the functionName as a String to my journalService and the arguments as an array of Serializable Objects. I demand the arguments to be Serializable because I need to persist them to an external database.

I contact my database via a REST/JSON framework, so I just want to post my journal entries to my database. My problem however is this: how can I put the Serializable Objects (the args) into my JSON body? And in what format do I need to store them in my database?


Solution

  • I would serialize the objects to a byte array/stream, and base64-encode the array/stream to get a printable String.

    At the database level, you can store the base64 string as a CLOB, or decode it to a byte array and store it as a BLOB.