Skip to content

Commit 5ebb5d0

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents cb45207 + 61685be commit 5ebb5d0

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Moshi Kotlin Extensions
2+
Kotlin extensions for Moshi, Make every thing you want with Moshi in just one line.
3+
4+
5+
### Add the JitPack repository to your build file
6+
```groovy
7+
allprojects {
8+
repositories {
9+
...
10+
maven { url 'https://jitpack.io' }
11+
}
12+
}
13+
```
14+
### Add dependency
15+
```groovy
16+
dependencies {
17+
implementation 'com.github.mazenrashed:MoshiKotlinExtensions:${LAST_VERSION}'
18+
}
19+
```
20+
21+
#### We have "Student" class to explan the samples
22+
```kotlin
23+
data class Student(var name: String)
24+
```
25+
26+
### Deserialize Json object
27+
```kotlin
28+
private val studentJson = "{\"name\":\"mazen\"}"
29+
val student: Student? = studentJson.deserialize<Student>()
30+
```
31+
32+
33+
### Deserialize Json array
34+
```kotlin
35+
private val studentsJson = "[{\"name\":\"Mazen\"},{\"name\":\"Mohammad\"}]"
36+
val students: List<Student>? = studentsJson.deserializeList()
37+
```
38+
39+
40+
### Serialize Json
41+
```kotlin
42+
private val student: Student = Student("mazen")
43+
val serializedObject = student.serialize()
44+
```
45+
46+
### Check if you can convert json to a particular type
47+
```kotlin
48+
val carConvertStudentJsonToStudent: Boolean = studentJson.canConvertTo(Student::class.java) //true
49+
```
50+
51+
### If you have a custom Moshi instance you want to use it (For example: To apply Moshi adapters)
52+
```kotlin
53+
MoshiExtensions.init(YOUR INSTANCE)
54+
```
55+
56+
57+
## Contributing
58+
59+
We welcome contributions!
60+
* ⇄ Pull requests and ★ Stars are always welcome.

0 commit comments

Comments
 (0)