Repository navigation
Description
Currently we use a json libary with a potential ugly license in web module (The software shall be used for good, not evil.). Others don't like it too. Android has a Apache licensed version of it here claiming that: "this class was written without inspecting the non-free org.json sourcecode"
So we should look into alternatives to replace this.
Also for several tasks we need a json parser in the core in the future. Such a parser should be fast, small, actively maintained, usages according to this, simple to use for basic configuration reading stuff, available on maven central and the Apache License is preferred. Also Java 7 is required for now, reading into POJOs would be good but not required.
- https://github.com/fangyidong/json-simple, this is actually the json.org project?!? 25KB, 200 stars, 420 usages, Apache, seem inactive
- https://github.com/ralfstx/minimal-json 30KB, 340 stars, MIT, 36 usages
- https://github.com/square/moshi ~100KB, 2000 stars, Apache, 16 usages
- https://github.com/jdereg/json-io ~100KB, 170 stars, Apache, 14 usages
- https://github.com/google/gson ~230KB, 5700 stars, Apache, 2360 usages
- http://johnzon.apache.org/index.html 240KB?, does not apply, Apache, <10 usages
- https://github.com/FasterXML/jackson-jr ~300KB (equivalent to databind, jackson core is 280KB), 80 stars, Apache, usages 3K for normal jackson, jackson-jr <20
- https://github.com/owlike/genson ~400KB,120 stars, Apache, <20
Probably a lot simpler would be if we pick one for now, create a simple interface and then could switch afterwards.
Activity
karussell commentedon Aug 22, 2016
The size is not that important as on Android side one could use ProGuard (cherry picking the classes), on server side it does not matter and for iOS we probably need a different implementation.
Hmmh, strange. Tested the additional size e.g. with gson and jackson and it added just 20kb to core although fully functional (serializing&deserializing) and original jars are like >200KB ... probably the jar-with-dependencies plugin already does cherry picking? No ... I just made a build mistake and the increase is as expected. Maven shade would be an option with
minimizeJar=truedevemux86 commentedon Aug 22, 2016
Well Gson has been more than good all this time. 👍
Also note that Android has a base JSON API integrated.
karussell commentedon Aug 22, 2016
Thanks! Looks like they just copied the JSON lib we are currently using. Despite the license thing.
karussell commentedon Aug 22, 2016
moshi looks even more streamlined (100KB) and is very similar to gson
devemux86 commentedon Aug 22, 2016
Does it require also Okio (75KB)?
karussell commentedon Aug 22, 2016
Ah, indeed. Still looks somehow cleaner: https://github.com/square/moshi#borrows-from-gson and okio is something we potentially need for okhttp at some point when replacing Downloader.
karussell commentedon Aug 22, 2016
But still investigating and jackson seems to be more widespread ... maybe we should wait for the JDK to use some standard json parser? There is already a JSR for it: https://jcp.org/en/jsr/detail?id=353
Potentially the interface is the best idea where we can easily replace the implementation depending on the underlying platform
devemux86 commentedon Aug 22, 2016
Many comparisons online for the two of them - Gson vs Jackson. 😄
When it'll be included, in Java 9 or 10? Also then Android is another story.
devemux86 commentedon Aug 27, 2016
@karussell can the json stuff be in another module, for not loading
corewith dependencies?karussell commentedon Aug 27, 2016
I'm not sure about this as we need this as core feature. Probably we can use normal classes but abstracting this away might be too much work - not sure if it is worth the effort.
BTW: see this json stuff implemented in #781
karussell commentedon Sep 6, 2016
Now #781 is merged. Also I found that something called (a bit misleading if you ask me) JSON-P is already standardized through JCP (
javax.json), already present in JavaEE7 and documented in latest javamagazinekarussell commentedon Sep 17, 2016
Ok, we now have a simple JSON parsing/writing module and can extend this. In the core module we should probably not use JSON but instead use simple POJOs. Also the XML creation should be probably moved out of the core. So the remaining task is to use our JSON parser/writer interface for all purposes and get rid of the org.json dependency.
[-]json library for core[/-][+]replace json.org library with own wrapper[/+]devemux86 commentedon Sep 17, 2016
@karussell well defined course of actions! 👍
karussell commentedon Nov 17, 2016
As we have managed to avoid using the JSON lib in the core we can also move to the more standard and more powerful jackson library, probably. Not sure. E.g. #855 adds jackson already as test dependency for csv parsing.
michaz commentedon Apr 28, 2017
The original goal, getting rid of the json.org library, is now accomplished. We still use gson in
reader-jsonfor now.