base on logansquare
The fastest JSON parsing and serializing library available for Android. Based on Jackson's streaming API, LoganSquare is able to consistently outperform GSON and Jackson's Databind library by 400% or more1. By relying on compile-time annotation processing to generate code, you know that your JSON will parse and serialize faster than any other method available.
By using this library, you'll be able to utilize the power of Jackson's streaming API without having to code tedius, low-level code involving JsonParser
s or JsonGenerator
s. Instead, just annotate your model objects as a @JsonObject
and your fields as @JsonField
s and we'll do the heavy lifting for you.
Don't believe it could improve upon Jackson Databind's or GSON's performance that much? Well, then check out the nifty graphs below for yourself. Not convinced? Feel free to build and run the BenchmarkDemo app included in this repository.
1 Note: Our "400% or more" performance improvement metric was determined using ART. While LoganSquare still comes out on top with Dalvik, it seems as though the comparison is much closer. The benchmarks shown are actual screenshots taken from a 2nd gen Moto X.
If your IDE is IntelliJ IDEA, please configure Annotation Processing first. If you want annotation processors to be run during compilation, select this checkbox and specify associated options:
Select this option, if you want IntelliJ IDEA to obtain the annotation processors from the project classpath. This is useful, for example, if you use a custom annotation processor as part of your project, or if the processor is stored in a .jar file attached to all the corresponding modules as a library.
Select this option and specify in the field to the right the path to the annotation processor, if it is not desirable to include the processor into the project or project libraries.
Use the fields below to define where the sources, generated by the annotation processors, are stored, and to override the default behaviour for a profile.
By default, the sources generated by annotation processors are stored relative to the module output directory.
Choose this option to override the default behaviour for a profile. At a later time, if you want to use the generated classes as your own sources, you can mark the corresponding directories as source roots.
2 On rebuild, the directories in which the generated sources are stored will be cleaned up as ordinary output directories. So it is not recommended to store non-generated sources in such directories. Otherwise, the corresponding sources will be lost on rebuild.
To add the library to your app's build.gradle file. If your Gradle plugin version is higher than 2.3.
dependencies {
annotationProcessor 'io.logansquarex:logansquareX-compiler:1.3.7'
compile 'io.logansquarex:logansquareX:1.3.7'
}
Below version 2.3
buildscript {
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
}
}
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
apt 'io.logansquarex:logansquareX-compiler:1.3.7'
compile 'io.logansquarex:logansquareX:1.3.7'
}
<dependency>
<groupId>io.logansquarex</groupId>
<artifactId>logansquareX</artifactId>
<version>1.3.7</version>
<type>pom</type>
</dependency>
For the curious, the buildscript and apply plugin lines add the apt plugin, which is what allows us to do compile-time annotation processing. The first dependency is what tells Gradle to process your JSON annotations, and the second dependency is our tiny 19kb runtime library that interfaces with the generated code for you.
Using LoganSquare is about as easy as it gets. Here are a few docs to get you started:
When using in Spring need to validate @Configuration classes,Specifically refer to this library(spring-configuration-validation-processor)
Like all libraries that generate dynamic code, Proguard might think some classes are unused and remove them. To prevent this, the following lines can be added to your proguard config file.
-keep class io.logansquarex.core.** { *; }
-keep @io.logansquarex.core.annotation.JsonObject class *
-keep class **$$JsonObjectMapper { *; }
We're BlueLine Labs, a mobile app development company based in Chicago. We love this city so much that we named our company after the blue line of the iconic 'L.' And what's one of the most popular stops on the blue line? Well, that would be Logan Square of course. Does it have anything to do with JSON? Nope, but we're okay with that.
- Jackson's streaming API for being a super-fast, awesome base for this project.
- Instagram's ig-json-parser for giving us the idea for this project.
- Jake Wharton's Butterknife for being a great reference for annotation processing and code generation.
- Annotation processors settings in IDEA for being Configure the official guidance of annotation processing in IDEA
Copyright 2018 LoganSquareX
Copyright 2015 BlueLine Labs, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.