I have a Kafka consumed record that will be parsed as JsValue with spray.json in scala, but I also have some data in the record's header, and I want to do:
Consume record with Alpakka Kafka library (done)
parse as json of type
JsValue
:kafkaRecord.record.value().parseJson
(also done)Append the record's header to that
JsValue
(HERE IS THE MAIN CONCERN)Header = kafkaRecord.record.headers()
Appending should include key[String]: value(header)
convert to pre-defined case class using
[JsValue].convertTo[<case class>]
Here is the consumed record for example:
{"id": 23, "features": "features_23"}
and want to append to it the Header to be as:
{"id": 23, "features": "features_23", "header_data":"Header_23"}
Then convert to case class:
case class recordOfKafka(id: Int, features: String, header_data: String)