Skip to content

Sample projects using Moshi Json parsing with codegen and reflection implemented with architecture components using data from The Movie Database

License

Notifications You must be signed in to change notification settings

alexforrester/android-moshi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 

Repository files navigation

android-moshi

Kotlin License

Sample projects using Android Architecture Components to illustrate Moshi parsing of JSON into Kotlin objects with codegen and reflection

Posting

Getting started using Moshi for JSON parsing with Kotlin: https://proandroiddev.com/getting-started-using-moshi-for-json-parsing-with-kotlin-5a460bf3935a

There are a number of libraries for parsing json into kotlin/java objects including Gson, Jackson and Moshi

Moshi is developed by Square and is targeted at the Android platform. It uses Kotlin language features to make parsing JSON data simpler and and more robust when handling null and absent responses. This repo illustrates some of Moshi's features and different implementations of how the library can be added in android projects using the reflection and codegen artifacts

App Description and Implementation

Both samples use androidx and ViewModel, LiveData and Navigation architecture components to display a list of Popular movies from The Movie Database which has been added as a file in the Assets folder. Selecting a movie will display a movie detail page including title, overview, image, the popularity of the movie in terms of the votes received and the genres it belongs to. The genres demonstrate bespoke parsing with Moshi to map Genre ids to Genres from the ingested JSON.

Unit tests use JUnit 5 and Mockk
Integration Tests use Espresso

Moshi Codegen and Reflection

The two samples differ only in how Moshi has been included and implemented with either the moshi-kotlin-codegen artifact for codegen and the moshi-kotlin artifact for reflection. More detail about the two options are in the official documentation.

License

Copyright 2019 Alex Forrester

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.

About

Sample projects using Moshi Json parsing with codegen and reflection implemented with architecture components using data from The Movie Database

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages