Reputation: 658
I am serializing a java object to JSON like below
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString( serializableObject );
When i am printing it in console i am seeing it properly .
{
"topicName" : "LVS",
"sellerId" : "TS",
"orderId" : "123456",
"lineIds" : [ {
"lineId" : "1",
"sublineIds" : [ "1" ]
} ]
}
this string is sending to a Kafak topic . But when i see topic the JSON showing as below . How i can avoid the \n and other slashes and get in kafka as a formatted json.
"inputPayload" : "{\n \"topicName\" : \"LVS\",\n \"sellerId\" : \"TS\",\n \"orderId\" :
\"123456\",\n \"lineIds\" : [ {\n \"lineId\" : \"1\",\n \"sublineIds\" : [ \"1\" ]\n } ]\n}"
Upvotes: 0
Views: 1406
Reputation: 1621
The data is getting stored properly. Whatever you're using to view it from Kafka is not interpreting the backslashes as escape characters and performing that formatting for display purposes, and that's fine. Presumably there is a process in your system that will read the data out of Kafka and deserialize it, and that will work fine with what you have here.
Upvotes: 2