What would be a dynamic and flexible way to transform XML or Json to Java object?
-
I am wondering that is there currently an API or a way to transform a XML or a JSON document into a Java object in a more dynamic and flexible way ? for example lets say this XML doesn't have the same element every time, sometimes it has 3 elements or sometimes it has 10 under the root. The naive way to implement it would be just manually hard-code all the possibilities in your java obj like in this case initialize all 10 instance variables, but I am looking for a more dynamic way that your obj can vary accordingly from xml document. In other words, if my XML document has 3 elements under the root then my java object would just have 3 instance variables.
-
Answer:
I am not quite sure whether this could resolve your issue, but I recommend you to use protocol buffer. It is more dynamic, robust and you can create a corresponding Java class, if you use its API - http://code.google.com/apis/protocolbuffers/docs/overview.html
Yigit Ihlamur at Quora Visit the source
Other answers
Use the Jackson library in the mode where the JSON tree is represented as the Jackson node classes (JsonNode, ObjectNode, ArrayNode), instead of bound to a set of your own, custom domain classes. Wonderfully dynamic.
Cornel Masson
Related Q & A:
- How to retrieve a JSON as an object in Android?Best solution by Stack Overflow
- What would be a good way to get into Julliard?Best solution by answers.yahoo.com
- What would be a creative way to make a timeline?Best solution by Yahoo! Answers
- What is the fastest and most efficient way to heal a canker sore?Best solution by Yahoo! Answers
- What would be a good, honest way for me to make some money online?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.