3

I need to import data from a file to my application. The obvious choices are XML and JSON. I have heard that JSON is lightweight and when parsed with Jackson, it gives good performance. But I have also heard that JiBX for XML is fast and uses XMLpull to give good performance. I would like to know which option to go for 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 JSON parsing.

dda
  • 6,030
  • 2
  • 25
  • 34
Deepak Senapati
  • 1,103
  • 2
  • 11
  • 30

3 Answers3

2

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

Excellent explanation been given in this article(especially read Note:). Xml you have

different types like DOM,PULL and SAX.But as per my knowledge, JSON is the best. For Large

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

For Jackson and gson. Have a glance of this link.

Jackson Vs. Gson

So when comparing with xml and json,i always suggest you to use json, since it's a light weight data for android. So it will be fast in loading and display the data. And gson,

it depends based on your project. Please see the above link comparsion.you will cleanly understand.

Community
  • 1
  • 1
Shadow
  • 6,864
  • 6
  • 44
  • 93
0

In addition, Jackson can also do XML if that's what you need, with https://github.com/FasterXML/jackson-dataformat-xml

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

StaxMan
  • 113,358
  • 34
  • 211
  • 239
0

I agree that in pure performance, JSON is going to be faster than JiBX.

You choice of tools should depend on the data you are transferring.

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

Use JSON if you want more flexibility. JSON doesn't check to see if your data is correct.

For example, when you create an object in JiBX:

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

When you retrieve the information in JiBX:

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

In JSON, your code would look like this:

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

To retrieve the transmitted information:

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

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

In either solution, your code is exactly the same in your Android client and your java service/server.

I hope this helps.

Don Corley - JiBX contributor

Don Corley
  • 496
  • 2
  • 7
  • There are many JSON libs, and many ways to use it -- although one way is to use "untyped" tree model (as shown above). Same is true with XML in general; JiBX is a data-binding tool and imposes more structure (similar to Jackson or GSON databinding for JSON). Just wanted to add as a note -- nothing wrong in above, adding for sake of completeness. – StaxMan Jan 26 '13 at 22:21