Skip to content

Commit

Permalink
Nix null check in writes, do !! on first value use
Browse files Browse the repository at this point in the history
  • Loading branch information
ZacSweers committed Feb 19, 2018
1 parent 90436da commit 8eb5bb4
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -623,18 +623,18 @@ private data class Adapter(
.addModifiers(OVERRIDE)
.addParameter(writer)
.addParameter(value)
.beginControlFlow("if (%N == null)", value)
.addStatement("%N.nullValue()", writer)
.addStatement("return")
.endControlFlow()
.addStatement("%N.beginObject()", writer)
.apply {
propertyList.forEach { prop ->
propertyList.forEachIndexed { index, prop ->
if (prop.nullable) {
beginControlFlow("if (%N.%L != null)", value, prop.name)
beginControlFlow("if (%N${if (index == 0) "!!" else ""}.%L != null)",
value,
prop.name)
}
addStatement("%N.name(%S)", writer, prop.serializedName)
addStatement("%N.toJson(%N, %N.%L)",
addStatement("%N.name(%S)",
writer,
prop.serializedName)
addStatement("%N.toJson(%N, %N${if (index == 0 && !prop.nullable) "!!" else ""}.%L)",
adapterProperties[prop.typeName to prop.jsonQualifiers]!!,
writer,
value,
Expand Down

0 comments on commit 8eb5bb4

Please sign in to comment.