ig-json-parser


Source link: https://github.com/Instagram/ig-json-parser

ig-json-parser

Fast JSON parser for java projects.

Getting started

The easiest way to get started is to look at maven-example. For more comprehensive examples, check out the unit tests or the demo.

Gradle

For Java projects, to use this library, add this to your build.gradle file:

allprojects {

repositories {

  maven {
 url 'https://jitpack.io' 
}

}
 
}
  ...  dependencies {

compile 'com.github.instagram.ig-json-parser:runtime:master-SNAPSHOT' // the runtime
compile 'com.github.instagram.ig-json-parser:processor:master-SNAPSHOT' // the annotation processor  
}

For Android projects using Android Studio 3.0+ or Gradle 4.0+, you can enable the annotation processor as following:

allprojects {

repositories {

  maven {
 url 'https://jitpack.io' 
}

}
 
}
  ...  dependencies {

annotationProcessor 'com.github.instagram.ig-json-parser:processor:master-SNAPSHOT'
implementation 'com.github.instagram.ig-json-parser:runtime:master-SNAPSHOT' 
}
 

If you are using older gradle versions, you can use old apt plugin to integrate the annotation processor:

allprojects {

repositories {

  maven {
 url 'https://jitpack.io' 
}

}
 
}
  ...  apply plugin: 'com.neenbedankt.android-apt'  dependencies {

apt 'com.github.instagram.ig-json-parser:processor:master-SNAPSHOT'
compile 'com.github.instagram.ig-json-parser:runtime:master-SNAPSHOT' 
}
 

If you are using other build sytems, please find instructions here

Requirements for model classes

There should be a package-visible no-argument constructor for each of your model classes. The fields also need to be package-visible.

Each class that needs a serializer/deserializer generated should be annotated with @JsonType. Each field that needs to be mapped to/from JSON should be annotated with @JsonField. The @JsonField annotation has one mandatory argument, which is the fieldname for the field in the JSON.

The following is an example of a very simple model class:

@JsonType class Dessert {

@JsonField(fieldName="type")
String type;
 @JsonField(fieldName="rating")
float rating; 
}

Serializer/deserializer

Compiling your model classes with the annotations will automatically generate the serializer and deserializer. They will be in a generated class with the same name as your class, except with the suffix __JsonHelper. For example, to deserialize the Dessert class above, simply run the code:

Dessert parsed = Dessert__JsonHelper.parseFromJson(inputJsonString);

To serialize a class, run:

String serialized = Dessert__JsonHelper.serializeToJson(dessertObject);

Supported data types

The following scalar types are supported:

  • String
  • boolean/Boolean
  • int/Integer
  • long/Long
  • float/Float
  • double/Double

If a json field is another dictionary, it can be represented by another model class. That model class must also have the @JsonType annotation.

Lists of objects are supported either as Java Lists or Queues.

Proguard

Add the following lines to your proguard-rules file:

-dontwarn sun.misc.Unsafe -dontwarn javax.annotation.** 

Advanced features

Postprocessing

TODO: Document this. See the documentation in common/src/main/java/com/instagram/common/json/annotation/JsonType.java in the meanwhile.

Customized parsing code

TODO: Document this. See the documentation in common/src/main/java/com/instagram/common/json/annotation/JsonField.java in the meanwhile.

Optional serializer generation

To save generating serializer code if you only need deserialization, serializer generation can be disabled or enabled globally and per-class. The default is to generate serializers for all classes. To disable generation globally, pass

-AgenerateSerializer=false 

to the command-line arguments of javac. To override the default generation option for a single class, see JsonType.generateSerializer().

Resources

SQLite Model Generator Eclipse plugin allows to generate SQLite models for Android projects using JSON schema file.

android-localization-helper helps to find missing or obsolete translations for android resources.

Usage:

alh.sh /path/to/android/project [arrays.xml]

You must specify android project folder. Second parameter is optional, it specifies resources filename (strings.xml by default).

This plugin generates Android string resource XML files from CSV file. Generation has to be invoked as additional gradle task.

Supported features:

  • non-translatable resources - translatable="false" XML attribute
  • auto-escaping double quotes, apostrophes and newlines
  • auto-quoting leading and trailing spaces
  • syntax validation - duplicated, empty, invalid names detection
  • comments

TokenAutoComplete is a Android Gmail style token auto-complete text field and filter. It's designed to have an extremely simple API to make it easy for anyone to implement this functionality while still exposing enough customization to let you make it awesome.

openpgp-api-lib provides methods to execute OpenPGP operations, such as sign, encrypt, decrypt, verify, and more without user interaction from background threads. This is done by connecting your client application to a remote service provided by OpenKeychain or other OpenPGP providers.

Auth0Client is a Gradle based Android library, to let developers have a basic Auth0 API.

This library is compatible from API 7 (Android 2.1).

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes