File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change
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.
You can’t perform that action at this time.
0 commit comments