简体   繁体   中英

Equivalent for objectmapper in python

I want to serialize my data in python for sending data to Kafka as a producer. :-)

and also there is a client with java that will deserialize messages with java and kafka.common.serialization

what is the equivalent for

objectmapper.writeValueAsString().getBytes()

in python?

in other words, how should I serialize data with python to be readable from the consumer side(java)?

thanks
a lot

You would need to get a dict object, then json.dumps it into the value of the Kafka record.

import json 
...

producer = KafkaProducer(...)

data = {"some":"data"}
producer.send(topic, value=json.dumps(data))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM