<commit_before>**NOTE: This library is still in beta!**
 
#Moshi: Pristine Models [![Build Status](https://travis-ci.org/jayrave/moshi-pristine-models.svg?branch=master)](https://travis-ci.org/jayrave/moshi-pristine-models) [ ![Download](https://api.bintray.com/packages/jayrave/kotlin/moshi-pristine-models/images/download.svg) ](https://bintray.com/jayrave/kotlin/moshi-pristine-models/_latestVersion) 
This is an add-on to [Moshi](https://github.com/square/moshi) which allows
 - to programmatically define mapping between models & JSON
 - to keep your models pristine => free of annotations & only concerned about the business logic
  
It is pretty easy to define the mappings!
```kotlin
data class User(val name: String, val age: Int)
```
```kotlin
class UserMapper : Mapper<User>() {
    val name = field(User::name, "user_name")
    val age = field(User::age, "user_age")
    
    override fun create(value: Value<User>) = User(value of name, value of age)
}
```

Once the mappings have been defined, `Moshi` has to be taught about these
```kotlin
val factory = PristineModelsJsonAdapterFactory.Builder()
        .add(User::class.java, UserMapper())
        .build()
        
val moshi = Moshi.Builder()
        .add(factory)
        // anything else you wanna teach moshi about
        .build()
```

Voila! Now `Moshi` knows how to map `User` to/from this JSON
```javascript
{
    "user_name": "<NAME>", <commit_msg>update README to talk about lazily initializing the mappers<commit_after>**NOTE: This library is still in beta!**
 
#Moshi: Pristine Models [![Build Status](https://travis-ci.org/jayrave/moshi-pristine-models.svg?branch=master)](https://travis-ci.org/jayrave/moshi-pristine-models) [ ![Download](https://api.bintray.com/packages/jayrave/kotlin/moshi-pristine-models/images/download.svg) ](https://bintray.com/jayrave/kotlin/moshi-pristine-models/_latestVersion) 
This is an add-on to [Moshi](https://github.com/square/moshi) which allows
 - to programmatically define mapping between models & JSON
 - to keep your models pristine => free of annotations & only concerned about the business logic
  
It is pretty easy to define the mappings!
```kotlin
data class User(val name: String, val age: Int)
```
```kotlin
class UserMapper : Mapper<User>() {
    val name = field(User::name, "user_name")
    val age = field(User::age, "user_age")
    
    override fun create(value: Value<User>) = User(value of name, value of age)
}
```

Once the mappings have been defined, `Moshi` has to be taught about these
```kotlin
val factory = PristineModelsJsonAdapterFactory.Builder()
        .add(User::class.java, UserMapper()) // there is an API to allow lazy initialization of mappers too
        .build()
        
val moshi = Moshi.Builder()
        .add(factory)
        // anything else you wanna teach moshi about
        .build()
```

Voila! Now `Moshi` knows how to map `User` to/from this JSON
```javascript
{
    "user_name": "<NAME>", 
{'fraction_non_alphanumeric': 0.13324315184308422, 'fraction_numerical': 0.0, 'mean_word_length': 4.00507614213198, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '434251', 'n_tokens_mistral': 972, 'n_tokens_neox': 913, 'n_words': 277}