• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to Serialize a POJO to an XML and Post it

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone please tell me how to serialize a POJO to create the following XML Body:



I've tried several online examples, but so far I have been unable to create it.

Also, once I can create this XML, how can I print it out to prove that I've successfully duplicated this XML?

Finally, once I can create this exact body, I plan on posting it to a Web Service, using REST Assured.

Thanks a lot for any help
 
Mark D Anthony
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mark D Anthony wrote:Can someone please tell me how to serialize a POJO to create the following XML Body:



I've tried several online examples, but so far I have been unable to create it.

Also, once I can create this XML, how can I print it out to prove that I've successfully duplicated this XML?

Finally, once I can create this exact body, I plan on posting it to a Web Service, using REST Assured.

Thanks a lot for any help



I have the following entity, can that be used to create this:

 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first thought is to use an editor which understands XML and support code folding. Then you can fold the code/nodes to their respective parent/child.
I know that Microsoft Visual Studio Code supports XML code folding.
 
Pete Letkeman
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a rough idea of what you could do for the LocationHolder nodes. This Will Not compile as is but it should give you a starting point
 
Pete Letkeman
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you have the proper POJO you can use JAXB as shown here https://www.mkyong.com/java/jaxb-hello-world-example/ to convert the XML values into object values.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!