Below is my input XML body, which is stored in src/test/resources:
<Customer>
<Id>1</Id>
<Name>John</Name>
<Age>23</Age>
</Customer>
I want to pass this XML body into the below java method, re-set the name & then post it to a HTTP URL:
public void updateXMLBodyAndPost(String newName(){
File file = new File("src\\test\resources\\customerDetails.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Customer customer1 = (Customer) jaxbUnmarshaller.unmarshal(file);
customer1.setName(newName);
System.out.println("Customer details: " + customer1.toString());
}
Above, i am able to set the new name. Then, I am trying to print out the updated XML body
But, instead what's being printed out is:
Customer details: Customer@7ba4f24f
What changes do I need to make to my code so the following is printed out in the console:
<Customer>
<Id>1</Id>
<Name>updatedName</Name>
<Age>23<Age>
</Customer>