Jolyglot


Source link: https://github.com/VictorAlbertos/Jolyglot

Jolyglot

Jolyglot allows to convert objects to and from Json without depending on any concrete implementation. Thus, you can happy code against this polyglot abstraction, and let the clients of your library choose whatever json provider which better suits their needs.

Available json providers

Available json providers supporting generics

Setup

Add JitPack repository in your build.gradle (top level module):

allprojects {

  repositories {

jcenter()

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

  
}
 
}

And add Jolyglot api module in the build.gradle of your library module:

dependencies {

  compile 'com.github.VictorAlbertos.Jolyglot:api:0.0.4' 
}

Ask to the clients of your library to add one of the next json providers:

dependencies {

  compile 'com.github.VictorAlbertos.Jolyglot:gson:0.0.4'
  compile 'com.github.VictorAlbertos.Jolyglot:jackson:0.0.4'
  compile 'com.github.VictorAlbertos.Jolyglot:moshi:0.0.4'
  compile 'com.github.VictorAlbertos.Jolyglot:fastjson:0.0.4' 
}

Usage

Instantiate Jolyglot.

Ask to the client of your library for an implementation of Jolyglot if your library doesn't need to deal with generics. Otherwise, ask for an instance of JolyglotGenerics.

Depending on the provider chosen by your client, the instance of Jolyglot will be created in one of the next ways:

Jolyglot jolyglot = new GsonSpeaker() Jolyglot jolyglot = new GsonSpeaker(gson) //overloaded constructor to customize the gson object.  Jolyglot jolyglot = new JacksonSpeaker() Jolyglot jolyglot = new JacksonSpeaker(objectMapper) //overloaded constructor to customize the objectMapper object.  Jolyglot jolyglot = new MoshiSpeaker() Jolyglot jolyglot = new MoshiSpeaker(moshi) //overloaded constructor to customize the moshi object.  Jolyglot jolyglot = new FastJsonSpeaker() 

Object to json.

jolyglot.toJson(object);

Json to object.

String json = ""; jolyglot.fromJson(json, Your.class);

Generic object to json.

Type type = jolyglot.newParameterizedType(YourParameterized.class, YourEnclosing.class);
 jolyglot.toJson(parameterizedObject, type);

Json to generic object.

String json = ""; Type type = jolyglot.newParameterizedType(YourParameterized.class, YourEnclosing.class);
 jolyglot.fromJson(json, type);

For a complete example go here.

Be aware that the idiosyncrasy of every underlying json provider still remains. Jolyglot is only an abstraction layer to honor this diversity, but, in the end, every java class serialized/deserialized needs to fulfill the requirements of every json provider.

Resources

An extension to Moshi that provides general purpose, simple and yet useful JsonAdapters that are not present in the main library.

A pure MVC base library on android. Using it, your code can be very clean in MVC pattern: light Activity, light View, light Model.

A download progressbar with cool animation.

A fluent API to integrate with Strava on Android apps.

A painless way to pick future time.

BottomSheetPickers is a set of new time pickers for Android that can be used in place of the stock time picker.

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