Last active
January 27, 2020 21:52
-
-
Save iht/4e1f03e505115c378145596ef9e47a1a to your computer and use it in GitHub Desktop.
Sample deserialization function for the Kafka2Avro pipelines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Returns an object of type T from a base64 encoded string. | |
* | |
* Overwrite this function for your deserialization code. In this example, we | |
* assume that Kafka contains plain old Java objects, encoded as base64 | |
* strings. | |
* | |
* @tparam T The type of the object to be recovered | |
* @param s String with a base64 encoded serialized object | |
*/ | |
def string2Object[T](s: String): T = { | |
val data: Array[Byte] = Base64.getDecoder.decode(s) | |
val ois: ObjectInputStream = new ObjectInputStream(new ByteArrayInputStream(data)) | |
val result: T = ois.readObject.asInstanceOf[T] | |
ois.close() | |
result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment