Comparison - XML ​​with JiBX or JSON with Jackson?

I need to import data from a file into my application. XML and JSON are the obvious choices. I've heard that JSON is lightweight and when done with Jackson it gives good performance. But I've also heard that JiBX for XML is fast and uses XMLpull for good performance. I would like to know which option to go and why ?. Can I get a speed comparison of XML with JiBX and JSON with Jackson? Also, I want to know if Google Gson is better than Jackson for parsing JSON.

+3


source to share


3 answers


Json is light weight. If you want to use large docs, JSon with Jackson.

A great explanation is given in this article (especially read the Note :). Xml you have

various types such as DOM, PULL and SAX. But as far as I know, JSON is the best. For large

docs prefer Jackson. http://www.javabeat.net/2011/05/androids-json-parser/



For Jackson and Gsson. Take a look at this link.

Jackson vs. Gson

So when comparing to xml and json, I always suggest you use json as it is lightweight data for Android. Thus, it will load and display data quickly. And gson,

depends on your project. See the link above. You will be clear.

+2


source


Alternatively, Jackson can do XML as well if you need it, https://github.com/FasterXML/jackson-dataformat-xml



I also agree that Jackson + JSON will be faster than any of the XML based solutions (as per https://github.com/eishay/jvm-serializers ). JibX is not bad and is probably fast enough for most uses (as are many, many other options). But if the speed is yours, Jackson will be faster than the choice you are talking about.

0


source


I agree that in pure performance JSON will be faster than JiBX.

The choice of tools depends on the data you are transferring.

Use JiBX if you have a specific data definition. JiBX is especially good at creating and finding complex data objects. JiBX makes sure your data is correct and will automatically convert your data to and from Java objects.

Use JSON if you need more flexibility. JSON does not validate data.

For example, when you create an object in JiBX:

Person person = new Person();
person.name = "Don";
person.age = 52;

      

When you fetch information in JiBX:

System.out.println("Name: " + person.name);
System.out.println("Age: " + person.age);

      

In JSON, your code will look like this:

JSONObject person = new JSONObject();
person.put("name", "Don");
person.put("age", new Integer(52));

      

To receive the transmitted information:

String name = person.get("name");
long age = person.get("age");

      

As you can see, JiBX code is better to read, but JSON is more flexible since you don't have a schema definition.

In any solution, your code is exactly the same for your android client and your java service / server.

Hope this helps.

Don Corley - JiBX member

0


source







All Articles