Don't linebreak keys with spaces (#1053)

* Don't linebreak keys with spaces

Resolves #1052

* Update kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt
This commit is contained in:
Zac Sweers
2019-12-12 02:53:25 -05:00
committed by GitHub
parent c3a1ba711c
commit 40a829ef18
2 changed files with 23 additions and 4 deletions

View File

@@ -121,10 +121,17 @@ internal class AdapterGenerator(
private val optionsProperty = PropertySpec.builder(
nameAllocator.newName("options"), JsonReader.Options::class.asTypeName(),
KModifier.PRIVATE)
.initializer("%T.of(${nonTransientProperties.joinToString(", ") {
// We manually put in quotes because we know the jsonName is already escaped
CodeBlock.of("\"%L\"", it.jsonName).toString()
}})", JsonReader.Options::class.asTypeName())
.initializer(
"%T.of(%L)",
JsonReader.Options::class.asTypeName(),
nonTransientProperties
.map {
// We manually put in quotes because we know the jsonName is already escaped.
val whitespaceSafeName = it.jsonName.replace(" ", "·")
CodeBlock.of("\"$whitespaceSafeName\"")
}
.joinToCode(", ")
)
.build()
private val constructorProperty = PropertySpec.builder(