Last active
January 27, 2020 21:53
-
-
Save iht/64f3fba4aec1002e7ac040da86dd5105 to your computer and use it in GitHub Desktop.
Sample serialization 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 a string representation of an object. | |
* | |
* Overwrite this function with your serialization code. In this example, we | |
* serialize the object and transform that into a base64 encoded string, | |
* which will be later on written to Kafka. | |
* | |
* @tparam T The type of the object ot be serialized. The type must be Serializable | |
* @param obj The object to be serialized | |
*/ | |
def object2String[T](obj: T): String = { | |
val bos = new ByteArrayOutputStream() | |
val oos = new ObjectOutputStream(bos) | |
oos.writeObject(obj) | |
oos.close() | |
val s: String = Base64.getEncoder.encodeToString(bos.toByteArray) | |
s | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment