I am working with IBM BPM (BAW) and trying to deserialize a business object (BO) that has been retrieved from the database in HEX format.
The data is extracted using the following SQL query:
DECLARE @BinaryData VARBINARY(MAX);
-- Assigning value to the variable
SELECT @BinaryData = DATA
FROM [BPMDB].[baw].[LSW_INSTANCE_DATA]
WHERE BPD_INSTANCE_ID = id;
-- Converting to HEX format
SELECT CONVERT(VARCHAR(MAX), @BinaryData, 2) AS HexData;
This returns a HEX string like the following:
0x3C54686973206973206120746573742E2E2E3E
My Goal:
- Convert this HEX string back into binary data.
- Deserialize this binary data into a working business object (BO) using IBM BPM.
From the IBM BPM documentation, I found that tw.system.serializer.fromXml works for textual XML data, but it does not support HEX or binary data formats.
What I Need:
- A way to convert the HEX string into a binary array.
- A method or code example (JavaScript or Java) to deserialize this binary data into a business object in IBM BPM.
I would greatly appreciate any working examples or suggestions for achieving this in IBM BPM. Thank you!
Василь Лаба is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
I can’t help you with the BPM part of the question (and in general you should limit your posts on SO to one question at a time), but the hex conversion is easy.
If you’re using Java 17 or better, then HexFormat is the way to go.
jshell> byte[] byteArray = java.util.HexFormat.of().parseHex("3C54686973206973206120746573742E2E2E3E");
byteArray ==> byte[19] { 60, 84, 104, 105, 115, 32, 105, 115, 3 ... 115, 116, 46, 46, 46, 62 }
If you’re using an older JVM, then going through BigInteger is the easiest way.
jshell> var temp = new BigInteger("3C54686973206973206120746573742E2E2E3E", 16);
temp ==> 1345397673462976114652632802180285954431790654
jshell> byte[] byteArray = temp.toByteArray();
byteArray ==> byte[19] { 60, 84, 104, 105, 115, 32, 105, 115, 3 ... 115, 116, 46, 46, 46, 62 }
If the Serialization for BPM is just java standard Serialization, you can convert the ByteArray to a ByteArrayInputStream and then deserialize that stream like any other. You can find many examples of how to do basic deserialization.