Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Opinions on parsing XML to JSON design

Options
  • 10-03-2013 6:16pm
    #1
    Closed Accounts Posts: 6,075 ✭✭✭


    Can any give their opinions on my design?

    Write Java web service to:
    • 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.

    Solution:
    • 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.

    What do you think?


Comments

  • Registered Users Posts: 2,791 ✭✭✭John_Mc


    Can any give their opinions on my design?

    Write Java web service to:
    • 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.

    Solution:
    • 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.

    What do you think?

    Your Car Information XML document can be searched using XPath expressions. This would be better than parsing into multiple car objects and iterating through.

    The Xpath expression should return the car(s) elements and from there you can convert into JSON objects.


  • Registered Users Posts: 2,021 ✭✭✭ChRoMe


    Use Google's gson lib for your marshaling of json.


Advertisement