Call external web service that returns an XML document as a String of 'Car' information.
Search this xml/string object for particular Car (bring me back all Fords).
Return all Fords as a JSON object.
Call external web service to get an XML file (as string) of all Car information.
Using JAXB, parse this String object into multiple Car objects.
Loop through the car objects and when I find a Ford, add it to a Car list.
Loop through Ford list and convert the list into a JSON object.
Return JSON object from web service.
I need my solution to demonstrate good coding practices, not just get a working solution.
H Paul wrote:So mechanically:
1. Use JAXB to unmarshall xm string into a list of xml annotated Car class (ford)
2. Then use Jackson Json to jsonize the list of xml annotated Car class.
Thanks for your reply.
I have made progress on the application and here it is:
I have witten the following methods:
Calls Interface 1 above returning all cars as a sample XML file in a string format (I must adhere to this exact format).
Generates a list of Car objects based on the XML file. The Car object has other sub objects, e.g. owner.
List<Cars> searchCars(String make)
Loops through the list of cars from above and finds any cards specified by make.
Return a new list of those cars.
Converts the list above into a JSON object.
This JSON object is then returned to the user.
The only issue I have is that the XML file and the JSON formats differ. E.g. instead of the Person object in the XML, the JSON just wants the person name, no other data. I must adhere to the JSON format given.
My question is, what is the best design for this? Would it be best to have to groups of Car objects (and sub objects), e.g. a group that are used to store the XML data, and a new group that are used to convert to JSON. I could write a convertor methods to do the conversion.
Would that be a good design or can you hink of a more effecient method? Is 2 groups of objects excessive?