I have a simple xml string which i want to pass to other service using restTemplate and want to serialize back to xml But i am getting constant error message com.fasterxml.jackson.core.JsonParseException: Unexpected character '"' (code 34) in prolog; expected '<'
Can you please help me what i am doing wrong -
Xml String
<?xml version='1.0' encoding='UTF-8'?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
KafkaTopicListener.java
KafkaListener(topics = "test-topic", groupId = "group-id", containerFactory = "kafkaListenerContainerFactory")
public void listen(String payload) throws Exception {
System.out.println("KafkaTopicListener.listen : payload ::"+payload.toString());// this is an xml string
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_XML);
headers.setAccept(Arrays.asList(MediaType.APPLICATION_XML));
HttpEntity<String> entity = new HttpEntity<String>(payload, headers);
restTemplate.postForEntity(validationURL, entity, String.class);
}
my receiver service(different app running on different port) is
ReceivingClass.java
@RequestMapping(value = "/testByteArray", method = RequestMethod.POST, consumes = "application/xml")
public void testByteArray(@RequestBody Object payload) throws IOException, ClassNotFoundException {
System.out.println("MailController.testByteArray String::"+payload.toString());
}
I am using jackson-dataformat-xml jar in my dependency for xml parsing.. but getting the parsing exception as below -
2021-03-11 13:01:27.531 WARN 25328 --- [nio-9003-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected character '"' (code 34) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character '"' (code 34) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]]
2021-03-11 13:01:27.764 WARN 25328 --- [nio-9003-exec-2] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Unexpected character '"' (code 34) in prolog; expected '<'
at [row,col {unknown-source}]: [1,1]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character '"' (code 34) in prolog; expected '<'