mirror of
https://github.com/msfjarvis/msfjarvis.dev.git
synced 2024-06-03 04:18:56 +05:30
content: reformat Moshi post code samples [deploy] [staging]
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
abd21cc14e
commit
a2bc4af910
|
@ -75,10 +75,12 @@ With less effort than one might think! Let's put down the basic building blocks.
|
|||
|
||||
```kotlin
|
||||
class TextPartsJsonAdapter {
|
||||
// Moshi is flexible about the parameters of these two methods, and for simpler types you will find it easier
|
||||
// to follow the example from the Moshi README which does not use JsonReader/JsonWriter and instead directly
|
||||
// converts items to and from their String representations. The method names are also not enforced, as Moshi
|
||||
// only uses the annotations to find relevant methods.
|
||||
// Moshi is flexible about the parameters of these two methods, and for simpler types
|
||||
// you will find it easier to follow the example from the Moshi README which does not
|
||||
// use JsonReader/JsonWriter and instead directly converts items to and from their String
|
||||
// representations. The method names are also not enforced, as Moshi only uses the
|
||||
// annotations to find relevant methods. The internal implementation of how they do it
|
||||
// can be found here: https://git.io/JLwnb
|
||||
|
||||
@FromJson
|
||||
fun fromJson(reader: JsonReader): TextParts? {
|
||||
|
@ -258,7 +260,8 @@ Now that you look at it, not really that different from what we did above. The o
|
|||
endObject()
|
||||
}
|
||||
- TODO("Not implemented")
|
||||
+ // Satisfy the typechecker and throw in case the JSON body didn't contain the 'heading' field at all
|
||||
+ // Satisfy the typechecker and throw in case the JSON body
|
||||
+ // didn't contain the 'heading' field at all
|
||||
+ require(heading != null) { "heading must not be null" }
|
||||
+ return TextParts(heading, body)
|
||||
}
|
||||
|
@ -316,7 +319,8 @@ class TextPartsJsonAdapter {
|
|||
}
|
||||
endObject()
|
||||
}
|
||||
// Satisfy the typechecker and throw in case the JSON body didn't contain the 'heading' field at all
|
||||
// Satisfy the typechecker and throw in case the JSON body
|
||||
// didn't contain the 'heading' field at all
|
||||
require(heading != null) { "heading must not be null" }
|
||||
return TextParts(heading, body)
|
||||
}
|
||||
|
@ -349,8 +353,7 @@ class TextPartsJsonAdapter {
|
|||
// Create the 'extras' field
|
||||
name("extras")
|
||||
if (value.body != null) {
|
||||
// If the body text exists, then start a new object and add a
|
||||
// body field
|
||||
// If the body text exists, then start a new object and add a body field
|
||||
beginObject()
|
||||
name("body")
|
||||
value(value.bodyText)
|
||||
|
|
Loading…
Reference in New Issue
Block a user