1

I have a use-case where input data is in xml format. It contains multiple fields where we are interested in reading only few fields.

Based on the different use-case, separate velocity templates would have to written to convert xml to json data.

I could not find a better guide on how to write velocity template to convert XML to json. Can someone please help us how to write velocity for conversion from XML to JSON.

Thanks in advance!

Amit Kumar
  • 377
  • 4
  • 17

1 Answers1

0

First convert your XML into a DTO, and then DTO into Json. You should split your architecture in more than just one layer. The data access layer will handle the WS call and the controller will know how to answer the REST call. Velocity is just a template engine, not a converting tool. You should check Jackson or Gson.

Dharman
  • 30,962
  • 25
  • 85
  • 135
TanvirChowdhury
  • 2,498
  • 23
  • 28
  • Yes, correcting myself - We have a data layer to convert XML into DTO. Then we're using velocity template to convert the java object into data-format requested by client. We've multiple clients where most of them require data in xml format, where we can easily convert our data to XML using velocity. But we have a new client which requires data in json format, so, we would need to convert the data in json format using velocity template. We are looking how we can build such velocity template. – Amit Kumar Oct 04 '21 at 10:43